Skip to content

Commit 46596f0

Browse files
sugunav14claude
andcommitted
Shorten comments from the review-fix rounds
Trim the added comments and test docstrings to two lines each. No code change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
1 parent 7a116e7 commit 46596f0

5 files changed

Lines changed: 13 additions & 22 deletions

File tree

‎examples/llm_qat/export.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ def get_model(
5050

5151
# Restore modelopt state for LoRA models. For QAT/QAD models from_pretrained call handles this.
5252
# For QLoRA the base checkpoint is quantized, so from_pretrained already restored the state.
53-
# Skipping the restore below is only safe because QATTrainer writes modelopt_state_train.pth at
54-
# trainer init from that same base state, so it carries no quantizer values from_pretrained did
55-
# not already load. Revisit this if the trainer ever snapshots state later in training.
53+
# Skipping is safe only because QATTrainer writes modelopt_state_train.pth at trainer init,
54+
# from that same base state.
5655
if hasattr(model, "peft_config") and not ModeloptStateManager.is_converted(model):
5756
modelopt_state = mto.load_modelopt_state(f"{ckpt_path}/modelopt_state_train.pth")
5857
restore_from_modelopt_state(model, modelopt_state)

‎modelopt/torch/opt/plugins/transformers.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,8 @@ def _restore_qtensor_wrappers(model, model_path):
110110
q_tensor_state = mode_config.get("metadata", {}).get("q_tensor_state", {})
111111
if not q_tensor_state:
112112
continue
113-
# PEFT nests the quantized linear as `<name>.base_layer`, and either side may carry that
114-
# suffix: the state is saved without it when the base model was compressed before adapters
115-
# were attached (`quantize.py --compress`) and with it when compressed after
116-
# (`QATTrainer._quantize_model`). Normalize both so the lookup works in either direction.
117-
# This assumes transformers injects adapters in place; moving the trainer to
118-
# `get_peft_model` would prefix module names with `base_model.model.` and break it.
113+
# PEFT nests the quantized linear as `<name>.base_layer`, and either the saved keys or the
114+
# live names may carry that suffix. Normalize both so the lookup works in either direction.
119115
q_tensor_state = {k.removesuffix(".base_layer"): v for k, v in q_tensor_state.items()}
120116

121117
pending = [
@@ -134,8 +130,8 @@ def _restore_qtensor_wrappers(model, model_path):
134130
)
135131
matched += 1
136132

137-
# A total miss means the module names were remapped by a wrapper we do not know about.
138-
# Warn here rather than letting it surface as an opaque shape error during dequantization.
133+
# A total miss means some wrapper renamed the modules. Warn instead of letting it surface
134+
# as an opaque shape error at dequantization.
139135
if pending and not matched:
140136
warnings.warn(
141137
f"Found {len(q_tensor_state)} compressed weight(s) in {modelopt_state_path} but "

‎tests/examples/llm_qat/test_llm_qat.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def test_qwen3_lora_qat_nvfp4(tiny_qwen3_path, tmp_path):
181181
cache_dir=cache_dir,
182182
)
183183

184-
# Step 3: Export. Unlike QLoRA this checkpoint is fake-quantized, so the calibrated amaxes
185-
# rather than packed weights are what must survive the load.
184+
# Step 3: Export. This checkpoint is fake-quantized, so the calibrated amaxes rather than
185+
# packed weights are what must survive the load.
186186
export_dir = tmp_path / "lora_qat_export"
187187
_run_export(str(lora_qat_output_dir), str(export_dir))
188188

@@ -193,9 +193,8 @@ def test_qwen3_lora_qat_nvfp4(tiny_qwen3_path, tmp_path):
193193
base_weights = load_file(base_model_dir / "model.safetensors")
194194
assert not any("base_layer" in k or k.endswith("_amax") for k in base_weights)
195195

196-
# LoRA freezes the base model, so exporting the PTQ checkpoint directly is a trusted oracle
197-
# for every calibrated value. Comparing against it catches scales that survive as keys but
198-
# were silently reset to defaults, which key-presence assertions alone would miss.
196+
# LoRA freezes the base model, so a direct PTQ export is a trusted oracle for every calibrated
197+
# value. This catches scales that keep their key but were reset to defaults.
199198
ptq_export_dir = tmp_path / "ptq_export"
200199
_run_export(str(ptq_output_dir), str(ptq_export_dir))
201200
reference = load_file(ptq_export_dir / "model.safetensors")

‎tests/gpu/torch/export/test_export.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ def test_postprocess_state_dict(state_dict, quantization, maxbound, expected_sta
262262
def test_postprocess_state_dict_qlora_strips_base_layer():
263263
"""Every QLoRA `base_layer.*` tensor needed for deployment must survive the rename.
264264
265-
`weight_scale_2` is the NVFP4 global scale and `bias` matters for architectures such as
266-
Qwen2; dropping either yields an undeployable checkpoint.
265+
Dropping the NVFP4 global scale or a bias yields an undeployable checkpoint.
267266
"""
268267
state_dict = {
269268
"layer1.base_layer.weight": torch.ones(4, 2, dtype=torch.uint8),

‎tests/unit/torch/opt/plugins/test_hf_patching.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,14 @@ def _compressed_model_and_state_dir(tmp_path, state_keyed_with_base_layer=False)
7878

7979
state = mto.modelopt_state(model)
8080
if state_keyed_with_base_layer:
81-
# Compressing after the adapters are attached (QATTrainer._quantize_model) saves the
82-
# keys with the peft suffix already in them.
81+
# Compressing after the adapters are attached saves the keys with the peft suffix.
8382
for _, mode_config in state["modelopt_state_dict"]:
8483
q_tensor_state = mode_config.get("metadata", {}).get("q_tensor_state", {})
8584
for key in list(q_tensor_state):
8685
q_tensor_state[f"{key}.base_layer"] = q_tensor_state.pop(key)
8786
torch.save(state, tmp_path / "modelopt_state.pth")
8887

89-
# transformers>=5 loads weights by assigning a plain Parameter holding the already-packed
90-
# data, which leaves the module without its QTensorWrapper.
88+
# transformers>=5 assigns a plain Parameter holding the packed data, dropping the wrapper.
9189
packed = model.fc.weight.data.clone()
9290
del model.fc._parameters["weight"]
9391
model.fc._parameters["weight"] = nn.Parameter(packed, requires_grad=False)

0 commit comments

Comments
 (0)