Skip to content

fix: MultiLoss.__add__ mutates original loss chain - #108

Open
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/losses-multiloss-add-mutates-original-loss
Open

fix: MultiLoss.__add__ mutates original loss chain#108
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/losses-multiloss-add-mutates-original-loss

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

Problem

fix: MultiLoss.add mutates original loss chain

Fix

Replace:

    def __add__(self, loss2):
        assert isinstance(loss2, MultiLoss)
        res = cur = copy(self)
        # find the end of the chain
        while cur._loss2 is not None:
            cur = cur._loss2
        cur._loss2 = loss2
        return res

with:

    def __add__(self, loss2):
        assert isinstance(loss2, MultiLoss)
        res = cur = deepcopy(self)
        # find the end of the chain
        while cur._loss2 is not None:
            cur = cur._loss2
        cur._loss2 = loss2
        return res

Files changed

  • dust3r/losses.py

Signed-off-by: Andrew White <andrewwhitecdw@users.noreply.github.com>
Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@andrewwhitecdw
andrewwhitecdw force-pushed the bugfix/losses-multiloss-add-mutates-original-loss branch from c0b3920 to 953413b Compare August 18, 2026 00:19
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