@@ -30,17 +30,15 @@ def test_calibration_options_default_to_disabled():
3030
3131def test_disabled_megatron_option_returns_no_te_calibration_config ():
3232 config = SimpleNamespace (
33- ckpt_transformer_engine_calibration = False ,
34- transformer_engine_calibration_decay = 0.5 ,
33+ ckpt_transformer_engine_calibration = False , transformer_engine_calibration_decay = 0.5
3534 )
3635
3736 assert fp8_utils .get_te_calibration_config (config ) is None
3837
3938
4039def test_calibration_option_requires_te_config_support (monkeypatch ):
4140 config = SimpleNamespace (
42- ckpt_transformer_engine_calibration = True ,
43- transformer_engine_calibration_decay = 0.123 ,
41+ ckpt_transformer_engine_calibration = True , transformer_engine_calibration_decay = 0.123
4442 )
4543 monkeypatch .setattr (fp8_utils .transformer_engine .pytorch , "QuantizationCalibrationConfig" , None )
4644 fp8_utils ._make_te_calibration_config .cache_clear ()
@@ -51,8 +49,7 @@ def test_calibration_option_requires_te_config_support(monkeypatch):
5149
5250def test_megatron_options_create_te_calibration_config ():
5351 config = SimpleNamespace (
54- ckpt_transformer_engine_calibration = True ,
55- transformer_engine_calibration_decay = 0.5 ,
52+ ckpt_transformer_engine_calibration = True , transformer_engine_calibration_decay = 0.5
5653 )
5754
5855 calibration_config = fp8_utils .get_te_calibration_config (config )
@@ -109,8 +106,7 @@ def legacy_fp8_autocast(*, enabled, fp8_recipe, fp8_group):
109106 monkeypatch .setattr (fp8_utils .transformer_engine .pytorch , "fp8_autocast" , legacy_fp8_autocast )
110107
111108 with pytest .raises (
112- RuntimeError ,
113- match = "--ckpt-transformer-engine-calibration.*accepts calibration_config" ,
109+ RuntimeError , match = "--ckpt-transformer-engine-calibration.*accepts calibration_config"
114110 ):
115111 fp8_utils .get_fp8_context (config )
116112
@@ -233,10 +229,10 @@ def test_calibration_amax_conversion_and_scale_inv_passthrough(monkeypatch):
233229 _disable_scale_collectives (monkeypatch )
234230 linear = torch .nn .Module ()
235231 linear .register_buffer (
236- "input_tensor_amax_fp8_delayed_scaling_te_ptq_calibrated " , torch .tensor ([896.0 ])
232+ "input_amax_fp8_delayed_scaling_te_ptq_calibrated " , torch .tensor ([896.0 ])
237233 )
238234 linear .register_buffer (
239- "weight_tensor_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
235+ "weight_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
240236 )
241237 model = torch .nn .Module ()
242238 model .add_module ("linear" , linear )
@@ -253,7 +249,7 @@ def test_calibration_amax_conversion_and_scale_inv_passthrough(monkeypatch):
253249def test_nvfp4_weight_amax_exports_secondary_weight_scale (monkeypatch ):
254250 _disable_scale_collectives (monkeypatch )
255251 linear = torch .nn .Module ()
256- linear .register_buffer ("weight_tensor_amax_nvfp4_te_ptq_calibrated " , torch .tensor ([2688.0 ]))
252+ linear .register_buffer ("weight_amax_nvfp4_te_ptq_calibrated " , torch .tensor ([2688.0 ]))
257253 model = torch .nn .Module ()
258254 model .add_module ("linear" , linear )
259255 state_dict = {"model" : {}}
@@ -263,6 +259,25 @@ def test_nvfp4_weight_amax_exports_secondary_weight_scale(monkeypatch):
263259 torch .testing .assert_close (state_dict ["model" ]["linear.weight_scale_2" ], torch .ones (1 ))
264260
265261
262+ def test_fused_module_tensor_names_export_distinct_scales (monkeypatch ):
263+ _disable_scale_collectives (monkeypatch )
264+ mlp = torch .nn .Module ()
265+ mlp .register_buffer (
266+ "fc1_input_scale_inv_fp8_current_scaling_te_ptq_calibrated" , torch .tensor ([0.25 ])
267+ )
268+ mlp .register_buffer (
269+ "fc2_input_scale_inv_fp8_current_scaling_te_ptq_calibrated" , torch .tensor ([0.5 ])
270+ )
271+ model = torch .nn .Module ()
272+ model .add_module ("mlp" , mlp )
273+ state_dict = {"model" : {}}
274+
275+ te_ext .add_ptq_calibration_metadata_to_state_dict (state_dict , [model ])
276+
277+ torch .testing .assert_close (state_dict ["model" ]["mlp.fc1_input_scale" ], torch .tensor ([0.25 ]))
278+ torch .testing .assert_close (state_dict ["model" ]["mlp.fc2_input_scale" ], torch .tensor ([0.5 ]))
279+
280+
266281def test_global_layer_fqn_uses_layer_number ():
267282 model = torch .nn .Module ()
268283 model .layers = torch .nn .ModuleList ([torch .nn .Module ()])
@@ -284,10 +299,10 @@ def test_expert_parallel_calibration_scales_are_gathered(monkeypatch):
284299 grouped_linear .num_gemms = 2
285300 grouped_linear ._pg_collection = SimpleNamespace (ep = ep_group )
286301 grouped_linear .register_buffer (
287- "input_gemm0_tensor_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
302+ "input_gemm0_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
288303 )
289304 grouped_linear .register_buffer (
290- "input_gemm1_tensor_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.5 ])
305+ "input_gemm1_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.5 ])
291306 )
292307 mlp = torch .nn .Module ()
293308 mlp .add_module ("linear_fc1" , grouped_linear )
@@ -321,7 +336,7 @@ def test_pipeline_parallel_calibration_states_are_merged(monkeypatch):
321336 model .pg_collection = SimpleNamespace (pp = pp_group )
322337 linear = torch .nn .Module ()
323338 linear .register_buffer (
324- "input_tensor_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
339+ "input_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
325340 )
326341 model .add_module ("linear" , linear )
327342
@@ -352,7 +367,7 @@ def test_pipeline_parallel_conflicting_calibration_states_are_rejected(monkeypat
352367 model .pg_collection = SimpleNamespace (pp = pp_group )
353368 linear = torch .nn .Module ()
354369 linear .register_buffer (
355- "input_tensor_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
370+ "input_scale_inv_fp8_current_scaling_te_ptq_calibrated " , torch .tensor ([0.25 ])
356371 )
357372 model .add_module ("linear" , linear )
358373
0 commit comments