Skip to content

Why is the model called twice here to generate ref_outputs, which are then used separately for the cross-entropy loss and the distillation loss? #7

@whitesweater

Description

@whitesweater

In model.py, the following code appears:

with torch.no_grad():
ref_outputs = self.codi(input_ids=ref_input_ids, output_hidden_states=True, attention_mask=ref_attention_mask)
ref_outputs_with_grad = self.codi(input_ids=ref_input_ids, output_hidden_states=True, attention_mask=ref_attention_mask)

Since these two forward passes are executed independently, their outputs may exhibit slight numerical differences.

Is this design choice primarily intended to reduce GPU memory usage?

Would it be feasible to use .detach() instead to achieve the same effect while avoiding redundant computation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions