Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for TensorRT inference compatibility on hopper architecture #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hydit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def get_args(default_args=None):
parser.add_argument("--no-fp16", dest="use_fp16", action="store_false")
parser.set_defaults(use_fp16=True)
parser.add_argument("--onnx-workdir", type=str, default="onnx_model", help="Path to save ONNX model")
parser.add_argument("--plugin-tag", type=str, default="others", choices=["others", "hopper"], help="Plugin architecture tag for choosing plugin package")


# Sampling
parser.add_argument("--batch-size", type=int, default=1, help="Per-GPU batch size")
Expand Down
7 changes: 6 additions & 1 deletion hydit/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ def __init__(self, args, models_root_path):

trt_dir = self.root / "model_trt"
engine_dir = trt_dir / "engine"
plugin_path = trt_dir / "fmha_plugins/9.2_plugin_cuda11/fMHAPlugin.so"

if self.args.plugin_tag == "others":
plugin_postfix = ""
elif self.args.plugin_tag == "hopper":
plugin_postfix = "_Hopper"
plugin_path = trt_dir / "fmha_plugins/9.2_plugin_cuda11/fMHAPlugin{}.so".format(plugin_postfix)
model_name = "model_onnx"

logger.info(f"Loading TensorRT model {engine_dir}/{model_name}...")
Expand Down
16 changes: 15 additions & 1 deletion trt/build_engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ else
export MODEL_ROOT=$(cd "$1"; pwd)
fi

if [ $# -ge 2 ]; then
PLUGIN_SUFFIX="$2"
else
PLUGIN_SUFFIX=""
fi
PLUGIN_PATH=${MODEL_ROOT}/t2i/model_trt/fmha_plugins/9.2_plugin_cuda11/fMHAPlugin${PLUGIN_SUFFIX}.so

if [ -e "$PLUGIN_PATH" ]; then
echo "Plugin exists."
else
echo "Invalid PLUGIN_SUFFIX or MODEL_ROOT"
exit 1
fi

export ONNX_WORKDIR=${MODEL_ROOT}/onnx_model
echo "MODEL_ROOT=${MODEL_ROOT}"
echo "ONNX_WORKDIR=${ONNX_WORKDIR}"
Expand Down Expand Up @@ -55,7 +69,7 @@ echo "Building TensorRT engine..."
ENGINE_DIR="${MODEL_ROOT}/t2i/model_trt/engine"
mkdir -p ${ENGINE_DIR}
ENGINE_PATH=${ENGINE_DIR}/model_onnx.plan
PLUGIN_PATH=${MODEL_ROOT}/t2i/model_trt/fmha_plugins/9.2_plugin_cuda11/fMHAPlugin.so


trtexec \
--onnx=${ONNX_WORKDIR}/export_modified_fmha/model.onnx \
Expand Down