-
Notifications
You must be signed in to change notification settings - Fork 371
Feat: Pre-quantized LLM model support #3740
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
base: main
Are you sure you want to change the base?
Conversation
62cb0f2
to
1f1cf7f
Compare
return model | ||
|
||
|
||
class TensorRTQuantizedLinear(torch.nn.Module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peri044 Is this something we might want to upstream to ModelOpt in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or pull into main torch-tensorrt as a pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess its somewhat HF specific, so remaining in this tool would make sense but are there some parts we could make generic for any sort of quantization workflow (e.g. torchao)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think quantize_model() can be moved to function like torch_tensorrt.dynamo.quantize(). Currently investigating how to separate the calibration data path from the quantization logic
tools/llm/quantize_utils.py
Outdated
|
||
hf_quant_algo = hf_quant_config.pop("quant_algo", None) | ||
if hf_quant_algo != "FP8" and hf_quant_algo != "NVFP4": | ||
raise RuntimeError("Only FP8 or NVFP4 quantization is supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would it be different for MXFP4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looked at quantization cfg in modelopt
NVFP4_DEFAULT_CFG NVFP4 has E4M3 scales and a block size is 16.
MXFP4_DEFAULT_CFG MXFP4 has E8M0 scales and a block size is 32.
19a4070
to
303775e
Compare
modelopt has changed their code structure in 0.35.0: |
tools/llm/quantize_utils.py
Outdated
input_amax = tensors.pop(input_scale_name) * 448.0 | ||
|
||
# Dequantize the weight using the scale factor | ||
dequantized_weight_data = module.weight.to(torch.float32) * weight_scale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check if precison is fp16 then .to(torch.float16) otherwise float32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that makes sense. I've updated it to use the same model precision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality looks good to me. Posted some comments on code restructuring
tools/llm/run_llm.py
Outdated
hf_quant_config = load_quantization_config(args.model) | ||
if hf_quant_config: | ||
model = convert_linear_to_tensorrt_quantized(model, hf_quant_config).cuda() | ||
print(f"Model converted to TensorRT quantized") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing this to a more informative message
7575120
to
efa63db
Compare
efa63db
to
3670829
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending CI failures
Description
Support pre-quantized HF models and post-training quantization (PTQ) option for run_llm.py
Fixes # (issue)
Type of change
Checklist: