-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[https://nvbugs/5463720][fix]: Naively handle per-layer MLP dimensions for Nemotron 49B #7016
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -461,11 +461,40 @@ def runtime_draft_len(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def set_lora_model_config(self, lora_target_modules: list[str], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trtllm_modules_to_hf_modules: dict[str, str]): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coarse_mlp_hidden_size = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Debug: Check what type self.model.model_config is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_engine.py - self.model.model_config type: {type(self.model.model_config)}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_engine.py - self.model.model_config dir: {dir(self.model.model_config)}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if hasattr(self.model.model_config, 'coarse_mlp_hidden_size'): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coarse_mlp_hidden_size = self.model.model_config.coarse_mlp_hidden_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_engine.py - coarse_mlp_hidden_size: {coarse_mlp_hidden_size}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_engine.py - coarse_mlp_hidden_size property not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Try direct access to see if it works | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coarse_mlp_hidden_size = self.model.model_config.coarse_mlp_hidden_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_engine.py - Direct access worked: {coarse_mlp_hidden_size}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except AttributeError as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: model_engine.py - Direct access failed: {e}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+464
to
+491
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid hasattr on properties that may raise; replace prints with robust getattr + logger.debug. coarse_mlp_hidden_size is a property that can raise ValueError for unsupported architectures. hasattr will evaluate the property and won’t catch ValueError, causing unexpected failures. Use getattr in a try/except, and use logger.debug instead of print. Apply this diff: - coarse_mlp_hidden_size = None
-
- # Debug: Check what type self.model.model_config is
- print(
- f"DEBUG: model_engine.py - self.model.model_config type: {type(self.model.model_config)}"
- )
- print(
- f"DEBUG: model_engine.py - self.model.model_config dir: {dir(self.model.model_config)}"
- )
-
- if hasattr(self.model.model_config, 'coarse_mlp_hidden_size'):
- coarse_mlp_hidden_size = self.model.model_config.coarse_mlp_hidden_size
- print(
- f"DEBUG: model_engine.py - coarse_mlp_hidden_size: {coarse_mlp_hidden_size}"
- )
- else:
- print(
- f"DEBUG: model_engine.py - coarse_mlp_hidden_size property not found"
- )
- # Try direct access to see if it works
- try:
- coarse_mlp_hidden_size = self.model.model_config.coarse_mlp_hidden_size
- print(
- f"DEBUG: model_engine.py - Direct access worked: {coarse_mlp_hidden_size}"
- )
- except AttributeError as e:
- print(f"DEBUG: model_engine.py - Direct access failed: {e}")
+ coarse_mlp_hidden_size = None
+ try:
+ coarse_mlp_hidden_size = getattr(self.model.model_config, 'coarse_mlp_hidden_size', None)
+ logger.debug("model_engine | coarse_mlp_hidden_size=%s", str(coarse_mlp_hidden_size))
+ except Exception as e:
+ # Property exists but inference failed; proceed without it.
+ logger.debug("model_engine | coarse_mlp_hidden_size unavailable: %s", e)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.lora_model_config = LoraModelConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lora_target_modules=lora_target_modules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trtllm_modules_to_hf_modules=trtllm_modules_to_hf_modules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hidden_size=self.model.config.hidden_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dtype=torch_dtype_to_str(self.model.config.torch_dtype)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dtype=torch_dtype_to_str(self.model.config.torch_dtype), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coarse_mlp_hidden_size=coarse_mlp_hidden_size) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def use_mrope(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -243,6 +243,7 @@ class LoraModelConfig: | |||||||||||||||||||||||||||||||||||||||||||
| trtllm_modules_to_hf_modules: dict[str, str] | ||||||||||||||||||||||||||||||||||||||||||||
| hidden_size: int | ||||||||||||||||||||||||||||||||||||||||||||
| dtype: str | ||||||||||||||||||||||||||||||||||||||||||||
| coarse_mlp_hidden_size: Optional[int] = None | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| class HfLoraLoader: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1133,14 +1134,107 @@ def load_from_model_dir(uid, model_dir, hf_config): | |||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| max_weight_size = max(w.size(0) for w in self._cpp_lora_weights[uid]) | ||||||||||||||||||||||||||||||||||||||||||||
| self._cpp_lora_weights[uid] = torch.stack( | ||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||
| torch.nn.functional.pad(w, (0, max_weight_size - w.size(0))) | ||||||||||||||||||||||||||||||||||||||||||||
| for w in self._cpp_lora_weights[uid] | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| # Handle both ModelConfig and LoraModelConfig types | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: model_config type: {type(model_config)}") | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_config has coarse_mlp_hidden_size: {hasattr(model_config, 'coarse_mlp_hidden_size')}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_config.coarse_mlp_hidden_size value: {model_config.coarse_mlp_hidden_size}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: model_config.coarse_mlp_hidden_size is None: {model_config.coarse_mlp_hidden_size is None}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1137
to
+1148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainReplace print-based debugging with logger.debug and trim verbosity. Using print in library code is noisy and hard to control. Prefer logger.debug (already configured as logger = logging.getLogger(name)). Collapse multiple prints into a single succinct line. Apply this diff: - print(f"DEBUG: model_config type: {type(model_config)}")
- print(
- f"DEBUG: model_config has coarse_mlp_hidden_size: {hasattr(model_config, 'coarse_mlp_hidden_size')}"
- )
- print(
- f"DEBUG: model_config.coarse_mlp_hidden_size value: {model_config.coarse_mlp_hidden_size}"
- )
- print(
- f"DEBUG: model_config.coarse_mlp_hidden_size is None: {model_config.coarse_mlp_hidden_size is None}"
- )
+ logger.debug(
+ "LoRA padding | model_config=%s | has_coarse=%s | coarse=%s",
+ type(model_config),
+ hasattr(model_config, "coarse_mlp_hidden_size"),
+ getattr(model_config, "coarse_mlp_hidden_size", None),
+ )Run to confirm no stray prints remain in lora_manager/model_engine: 🏁 Script executed: #!/bin/bash
rg -nP '^\s*print\(' tensorrt_llm/lora_manager.py tensorrt_llm/_torch/pyexecutor/model_engine.pyLength of output: 3027 Mandate: Replace all Your grep shows numerous stray • Files and ranges needing refactor:
• Primary change (example for LoraManager snippet at 1137–1148): - print(f"DEBUG: model_config type: {type(model_config)}")
- print(
- f"DEBUG: model_config has coarse_mlp_hidden_size: {hasattr(model_config, 'coarse_mlp_hidden_size')}"
- )
- print(
- f"DEBUG: model_config.coarse_mlp_hidden_size value: {model_config.coarse_mlp_hidden_size}"
- )
- print(
- f"DEBUG: model_config.coarse_mlp_hidden_size is None: {model_config.coarse_mlp_hidden_size is None}"
- )
+ logger.debug(
+ "LoRA padding | model_config=%s | has_coarse=%s | coarse=%s",
+ type(model_config),
+ hasattr(model_config, "coarse_mlp_hidden_size"),
+ getattr(model_config, "coarse_mlp_hidden_size", None),
+ )Apply the same pattern to all other debug prints:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| # Handle both ModelConfig and LoraModelConfig types | ||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||
| hasattr(model_config, "coarse_mlp_hidden_size") | ||||||||||||||||||||||||||||||||||||||||||||
| and model_config.coarse_mlp_hidden_size is not None | ||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: INSIDE load_from_hf: model_config.coarse_mlp_hidden_size: " | ||||||||||||||||||||||||||||||||||||||||||||
| f"{model_config.coarse_mlp_hidden_size}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| M_coarse = model_config.coarse_mlp_hidden_size | ||||||||||||||||||||||||||||||||||||||||||||
| H = model_config.hidden_size | ||||||||||||||||||||||||||||||||||||||||||||
| rank = int(hf_config["r"]) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - M_coarse: {M_coarse}") | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - tp_size: {tp_size}") | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - H (hidden_size): {H}") | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - rank: {rank}") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| M_coarse_tp = M_coarse * tp_size | ||||||||||||||||||||||||||||||||||||||||||||
| max_weight_size = rank * M_coarse_tp + rank * H | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1167
to
+1169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TP double-counting in max_weight_size; coarse_mlp_hidden_size is already TP-split. coarse_mlp_hidden_size returns the TP-split M value. Multiplying by tp_size again inflates padding by tp_size, wasting memory significantly (especially on 49B). Compute with the TP-split value directly. Apply this diff: - M_coarse_tp = M_coarse * tp_size
- max_weight_size = rank * M_coarse_tp + rank * H
+ // coarse_mlp_hidden_size is already TP-split; do not multiply by tp_size again.
+ M_coarse_tp = M_coarse
+ // For MLP up/gate or down, flattened size per module is rank*(M_coarse_tp + H).
+ // This upper-bounds attention modules too since M_coarse_tp >= H in typical configs.
+ calc_max_weight_size = rank * (M_coarse_tp + H)
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - M_coarse_tp: {M_coarse_tp}") | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - max_weight_size calculation: " | ||||||||||||||||||||||||||||||||||||||||||||
| f"{rank} * {M_coarse_tp} + {rank} * {H} = {max_weight_size}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Debug actual weights before padding | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Number of weight tensors: {len(self._cpp_lora_weights[uid])}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| for i, w in enumerate(self._cpp_lora_weights[uid]): | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Weight {i} shape: {w.shape}, size(0): {w.size(0)}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Debug the actual maximum weight size | ||||||||||||||||||||||||||||||||||||||||||||
| actual_max_weight_size = max(w.size(0) for w in self._cpp_lora_weights[uid]) | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Actual max weight size: {actual_max_weight_size}") | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Calculated max_weight_size: {max_weight_size}") | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Difference: {max_weight_size - actual_max_weight_size}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1186
to
+1191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against negative padding; ensure computed max covers actual max. If calc_max_weight_size underestimates (e.g., DoRA adds a magnitude vector), padding_needed becomes negative and F.pad will error. Use the actual maximum size as a floor. Apply this diff: - actual_max_weight_size = max(w.size(0) for w in self._cpp_lora_weights[uid])
- print(f"DEBUG: load_from_hf - Actual max weight size: {actual_max_weight_size}")
- print(f"DEBUG: load_from_hf - Calculated max_weight_size: {max_weight_size}")
- print(
- f"DEBUG: load_from_hf - Difference: {max_weight_size - actual_max_weight_size}"
- )
+ actual_max_weight_size = max(w.size(0) for w in self._cpp_lora_weights[uid])
+ # Account for possible DoRA magnitude vector (+M_coarse_tp) by taking the max with actual.
+ max_weight_size = max(calc_max_weight_size, actual_max_weight_size)
+ logger.debug(
+ "LoRA padding | calc=%d actual=%d final=%d",
+ calc_max_weight_size, actual_max_weight_size, max_weight_size
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Debug module-specific sizes | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Number of modules: {len(self._cpp_lora_weights[uid])}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| print("DEBUG: load_from_hf - Module sizes by index:") | ||||||||||||||||||||||||||||||||||||||||||||
| for i, w in enumerate(self._cpp_lora_weights[uid]): | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Module {i}: {w.size(0)}") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Debug which modules are failing | ||||||||||||||||||||||||||||||||||||||||||||
| print("DEBUG: load_from_hf - Checking which modules might fail validation:") | ||||||||||||||||||||||||||||||||||||||||||||
| for i, w in enumerate(self._cpp_lora_weights[uid]): | ||||||||||||||||||||||||||||||||||||||||||||
| if w.size(0) < max_weight_size: | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Module {i} will be padded: {w.size(0)} -> {max_weight_size}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Module {i} no padding needed: {w.size(0)}") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||
| # Final fallback: use the maximum size of actual weights | ||||||||||||||||||||||||||||||||||||||||||||
| max_weight_size = max(w.size(0) for w in self._cpp_lora_weights[uid]) | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Using fallback max_weight_size: {max_weight_size}") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Final max_weight_size: {max_weight_size}") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Debug padding process | ||||||||||||||||||||||||||||||||||||||||||||
| padded_weights = [] | ||||||||||||||||||||||||||||||||||||||||||||
| for i, w in enumerate(self._cpp_lora_weights[uid]): | ||||||||||||||||||||||||||||||||||||||||||||
| padding_needed = max_weight_size - w.size(0) | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Weight {i}: original size {w.size(0)}, padding {padding_needed}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| padded_w = torch.nn.functional.pad(w, (0, padding_needed)) | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"DEBUG: load_from_hf - Weight {i}: padded size {padded_w.size(0)}") | ||||||||||||||||||||||||||||||||||||||||||||
| padded_weights.append(padded_w) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1219
to
+1228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Safer padding: clamp to zero and avoid per-weight print loops. Even with the fix above, clamping is a safe guard and avoids crash on rare edge-cases. Replace prints with a single debug if needed. Apply this diff: - padded_weights = []
- for i, w in enumerate(self._cpp_lora_weights[uid]):
- padding_needed = max_weight_size - w.size(0)
- print(
- f"DEBUG: load_from_hf - Weight {i}: original size {w.size(0)}, padding {padding_needed}"
- )
- padded_w = torch.nn.functional.pad(w, (0, padding_needed))
- print(f"DEBUG: load_from_hf - Weight {i}: padded size {padded_w.size(0)}")
- padded_weights.append(padded_w)
+ padded_weights = []
+ for i, w in enumerate(self._cpp_lora_weights[uid]):
+ padding_needed = max_weight_size - w.size(0)
+ if padding_needed < 0:
+ # Should not happen with the guard above; fall back defensively.
+ logger.warning("LoRA padding | negative padding=%d at idx=%d; widening to actual size", padding_needed, i)
+ padding_needed = 0
+ padded_weights.append(torch.nn.functional.pad(w, (0, padding_needed)))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| self._cpp_lora_weights[uid] = torch.stack(padded_weights) | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Final stacked weights shape: {self._cpp_lora_weights[uid].shape}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| self._cpp_lora_config[uid] = torch.stack([c for c in self._cpp_lora_config[uid]]) | ||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||
| f"DEBUG: load_from_hf - Final stacked config shape: {self._cpp_lora_config[uid].shape}" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| for uid, model_dir, hf_config in zip(new_uids, new_model_dirs, lora_hf_configs): | ||||||||||||||||||||||||||||||||||||||||||||
| load_from_model_dir(uid, model_dir, hf_config) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
Log after-check makes debugging impossible on failure; move log before check and reuse computed sizes. Also fix typo "to few" → "too few".
If the size check fails, the debug line never emits. Compute expected/actual once, log, then assert using the computed values. This also fixes the user-facing message grammar.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents