Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcore_bridge/tuners/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def merge(self, safe_merge: bool = False, adapter_names: Optional[list[str]] = N
orig_weights = [weight.data.clone() for weight in orig_weights]
delta_weights = self.get_delta_weights(active_adapter)
for orig_weight, delta_weight in zip(orig_weights, delta_weights):
orig_weight += delta_weight
orig_weight.data += delta_weight

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the .data attribute is discouraged in modern PyTorch because it bypasses autograd tracking and safety checks, which can lead to silent bugs. To safely perform this in-place addition without triggering autograd errors (since delta_weight may require gradients), you should detach delta_weight using .detach() instead.

Suggested change
orig_weight.data += delta_weight
orig_weight += delta_weight.detach()

if not all(torch.isfinite(orig_weights[i]).all() for i in range(len(orig_weights))):
raise ValueError(
f'NaNs detected in the merged weights. The adapter {active_adapter} seems to be broken')
Expand Down
Loading