Skip to content

update lora add#98

Merged
Jintao-Huang merged 1 commit into
modelscope:mainfrom
Jintao-Huang:update_lora_add
May 27, 2026
Merged

update lora add#98
Jintao-Huang merged 1 commit into
modelscope:mainfrom
Jintao-Huang:update_lora_add

Conversation

@Jintao-Huang

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the weight merging logic in src/mcore_bridge/tuners/lora.py to use orig_weight.data += delta_weight. The reviewer noted that accessing the .data attribute directly is discouraged in modern PyTorch because it bypasses autograd tracking and safety checks. They suggested using .detach() instead to safely perform the in-place addition.

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()

@Jintao-Huang
Jintao-Huang merged commit 73695c2 into modelscope:main May 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant