-
Notifications
You must be signed in to change notification settings - Fork 365
Test fp4: Lluo/fp4 try out #3521
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
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.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/nvfp4_quantize.py 2025-05-15 17:28:16.606815+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/nvfp4_quantize.py 2025-05-15 17:28:40.517973+00:00
@@ -140,12 +140,11 @@
return dequantized_data
# TODO: to remove it this is to make sure our global scale and block scale calculation is correct during debugging
def _test_weights_scaling_factor(
- weights_tensor: torch.Tensor,
- global_scale: torch.Tensor
+ weights_tensor: torch.Tensor, global_scale: torch.Tensor
) -> None:
import modelopt.core.torch.quantization.qtensor.nvfp4_tensor as nvfp4_tensor
import modelopt.onnx.quantization.quant_utils as quant_utils
@@ -192,11 +191,13 @@
"""
import modelopt.core.torch.quantization.qtensor.nvfp4_tensor as nvfp4_tensor
block_scale_fp8 = nvfp4_tensor.NVFP4QTensor.get_weights_scaling_factor(
- weights_tensor, 16, global_scale,
+ weights_tensor,
+ 16,
+ global_scale,
)[0]
weights_tensor_scaled = nvfp4_tensor.NVFP4QTensor.quantize(
weights_tensor,
16,
@@ -205,11 +206,13 @@
)[0]._quantized_data
block_scale_fp8 = get_trt_tensor(ctx, block_scale_fp8, name + "_block_scale_fp8")
global_scale = to_torch(global_scale, None)
global_scale = get_trt_tensor(ctx, global_scale, name + "_global_scale")
- weights_fp4_represented_in_uint8 = get_trt_tensor(ctx, weights_tensor_scaled, name + "_weights_fp4_represented_in_uint8")
+ weights_fp4_represented_in_uint8 = get_trt_tensor(
+ ctx, weights_tensor_scaled, name + "_weights_fp4_represented_in_uint8"
+ )
# dequantize block scale from fp8 to float32
dequantize_block_scale_layer = ctx.net.add_dequantize(
block_scale_fp8,
global_scale,
@@ -248,6 +251,5 @@
) # amax is calculated from input_tensor.abs().amax().float()
global_scale = torch.divide(amax, 6 * 448)
if global_scale == 0:
global_scale = 1.0
return global_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.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/nvfp4_quantize.py 2025-05-15 21:33:37.025993+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/nvfp4_quantize.py 2025-05-15 21:33:59.004002+00:00
@@ -140,12 +140,11 @@
return dequantized_data
# TODO: to remove it this is to make sure our global scale and block scale calculation is correct during debugging
def _test_weights_scaling_factor(
- weights_tensor: torch.Tensor,
- global_scale: torch.Tensor
+ weights_tensor: torch.Tensor, global_scale: torch.Tensor
) -> None:
import modelopt.core.torch.quantization.qtensor.nvfp4_tensor as nvfp4_tensor
import modelopt.onnx.quantization.quant_utils as quant_utils
@@ -192,11 +191,13 @@
"""
import modelopt.core.torch.quantization.qtensor.nvfp4_tensor as nvfp4_tensor
block_scale_fp8 = nvfp4_tensor.NVFP4QTensor.get_weights_scaling_factor(
- weights_tensor, 16, global_scale,
+ weights_tensor,
+ 16,
+ global_scale,
)[0]
weights_tensor_scaled = nvfp4_tensor.NVFP4QTensor.quantize(
weights_tensor,
16,
@@ -205,11 +206,13 @@
)[0]._quantized_data
block_scale_fp8 = get_trt_tensor(ctx, block_scale_fp8, name + "_block_scale_fp8")
global_scale = to_torch(global_scale, None)
global_scale = get_trt_tensor(ctx, global_scale, name + "_global_scale")
- weights_fp4_represented_in_uint8 = get_trt_tensor(ctx, weights_tensor_scaled, name + "_weights_fp4_represented_in_uint8")
+ weights_fp4_represented_in_uint8 = get_trt_tensor(
+ ctx, weights_tensor_scaled, name + "_weights_fp4_represented_in_uint8"
+ )
# dequantize block scale from fp8 to float32
dequantize_block_scale_layer = ctx.net.add_dequantize(
block_scale_fp8,
global_scale,
@@ -248,6 +251,5 @@
) # amax is calculated from input_tensor.abs().amax().float()
global_scale = torch.divide(amax, 6 * 448)
if global_scale == 0:
global_scale = 1.0
return global_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.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/nvfp4_quantize.py 2025-05-15 22:36:44.918571+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/nvfp4_quantize.py 2025-05-15 22:37:09.722122+00:00
@@ -140,12 +140,11 @@
return dequantized_data
# TODO: to remove it this is to make sure our global scale and block scale calculation is correct during debugging
def _test_weights_scaling_factor(
- weights_tensor: torch.Tensor,
- global_scale: torch.Tensor
+ weights_tensor: torch.Tensor, global_scale: torch.Tensor
) -> None:
import modelopt.core.torch.quantization.qtensor.nvfp4_tensor as nvfp4_tensor
import modelopt.onnx.quantization.quant_utils as quant_utils
@@ -192,11 +191,13 @@
"""
import modelopt.core.torch.quantization.qtensor.nvfp4_tensor as nvfp4_tensor
block_scale_fp8 = nvfp4_tensor.NVFP4QTensor.get_weights_scaling_factor(
- weights_tensor, 16, global_scale,
+ weights_tensor,
+ 16,
+ global_scale,
)[0]
weights_tensor_scaled = nvfp4_tensor.NVFP4QTensor.quantize(
weights_tensor,
16,
@@ -205,11 +206,13 @@
)[0]._quantized_data
block_scale_fp8 = get_trt_tensor(ctx, block_scale_fp8, name + "_block_scale_fp8")
global_scale = to_torch(global_scale, None)
global_scale = get_trt_tensor(ctx, global_scale, name + "_global_scale")
- weights_fp4_represented_in_uint8 = get_trt_tensor(ctx, weights_tensor_scaled, name + "_weights_fp4_represented_in_uint8")
+ weights_fp4_represented_in_uint8 = get_trt_tensor(
+ ctx, weights_tensor_scaled, name + "_weights_fp4_represented_in_uint8"
+ )
# dequantize block scale from fp8 to float32
dequantize_block_scale_layer = ctx.net.add_dequantize(
block_scale_fp8,
global_scale,
@@ -248,6 +251,5 @@
) # amax is calculated from input_tensor.abs().amax().float()
global_scale = torch.divide(amax, 6 * 448)
if global_scale == 0:
global_scale = 1.0
return global_scale
-
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: