Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Model Optimizer Changelog (Linux)
- Add support for multi-node PTQ and export with FSDP2 in ``examples/llm_ptq/multinode_ptq.py``. See `examples/llm_ptq/README.md <https://github.com/NVIDIA/TensorRT-Model-Optimizer/tree/main/examples/llm_ptq#multi-node-post-training-quantization-with-fsdp2>`_ for more details.
- Add support for Nemotron Nano VL v1 & v2 models in FP8/NVFP4 PTQ workflow.
- Add flags ``nodes_to_include`` and ``op_types_to_include`` in AutoCast to force-include nodes in low precision, even if they would otherwise be excluded by other rules.
- Add support for ``torch.compile`` and benchmarking in ``examples/diffusers/quantization/diffusion_trt.py``.

**Documentation**

Expand Down
9 changes: 7 additions & 2 deletions examples/diffusers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,16 @@ Generate images for the quantized checkpoint with the following [Script](./quant
python diffusion_trt.py \
--model {sdxl-1.0|sdxl-turbo|sd3-medium|flux-dev} \
--prompt "A cat holding a sign that says hello world" \
[--override-model-path /path/to/model] \
[--restore-from ./{MODEL}_fp8.pt] \
[--onnx-load-path {ONNX_DIR}] \
[--trt-engine-load-path {ENGINE_DIR}] \
[--dq_only] \
[--torch]
[--dq-only] \
[--torch] \
[--save-image-as /path/to/image] \
[--benchmark] \
[--torch-compile] \
[--skip-image]
```

This script will save the output image as `./{MODEL}.png` and report the latency of the TensorRT backbone.
Expand Down
16 changes: 4 additions & 12 deletions examples/diffusers/quantization/diffusion_trt.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ def main():
default=None,
help="Path to the model if not using default paths in MODEL_ID mapping.",
)
parser.add_argument(
"--model-dtype",
type=str,
default="Half",
choices=["Half", "BFloat16", "Float"],
help="Precision used to load the model.",
)
parser.add_argument(
"--restore-from", type=str, default=None, help="Path to the modelopt quantized checkpoint"
)
Expand Down Expand Up @@ -170,28 +163,27 @@ def main():

pipe = PipelineManager.create_pipeline_from(
MODEL_ID[args.model],
dtype_map[args.model_dtype],
override_model_path=args.override_model_path,
)

# Save the backbone of the pipeline and move it to the GPU
add_embedding = None
backbone = None
model_dtype = None
if hasattr(pipe, "transformer"):
backbone = pipe.transformer
model_dtype = "Bfloat16"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use the dtype from the model or this has to be setup like the hardcoded way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have hardcoded the dtype in create_pipeline_from() function, so we will have to use this in the hardcoded way.

elif hasattr(pipe, "unet"):
backbone = pipe.unet
add_embedding = backbone.add_embedding
model_dtype = "Half"
else:
raise ValueError("Pipeline does not have a transformer or unet backbone")

if args.restore_from:
mto.restore(backbone, args.restore_from)

if args.torch_compile:
assert args.model_dtype in ["BFloat16", "Float", "Half"], (
"torch.compile() only supports BFloat16 and Float"
)
print("Compiling backbone with torch.compile()...")
backbone = torch.compile(backbone, mode="max-autotune")

Expand All @@ -203,7 +195,7 @@ def main():
pipe.to("cuda")

if args.benchmark:
benchmark_model(pipe, args.prompt, model_dtype=args.model_dtype)
benchmark_model(pipe, args.prompt, model_dtype=model_dtype)

if not args.skip_image:
generate_image(pipe, args.prompt, image_name)
Expand Down