Skip to content
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

FEAT: [SFTTrainer] Add eval_packing #1369

Merged
merged 1 commit into from
Feb 27, 2024
Merged

FEAT: [SFTTrainer] Add eval_packing #1369

merged 1 commit into from
Feb 27, 2024

Conversation

younesbelkada
Copy link
Contributor

Fixes: #1343

Adds the possibility for users to enable/disable packing for the eval_dataset using a ternary logic (if None -> packing else eval_packing)

cc @lvwerra @kashif

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@younesbelkada younesbelkada merged commit 7712d42 into main Feb 27, 2024
9 checks passed
@younesbelkada younesbelkada deleted the add-packing-eval branch February 27, 2024 10:19
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
@federicoBetti
Copy link

federicoBetti commented Jul 13, 2024

Hi @younesbelkada ,
i'm using eval_packing = False to better compute metrics on the evaluation dataset.
The problem is when using it together with batch_eval_metrics, the Trainer crashes when it tries to delete the tensors of losses, logits, labels, inputs.

            if self.args.batch_eval_metrics:
                if self.compute_metrics is not None and logits is not None and labels is not None:
                    is_last_step = self.accelerator.gradient_state.end_of_dataloader
                    if args.include_inputs_for_metrics:
                        metrics = self.compute_metrics(
                            EvalPrediction(predictions=logits, label_ids=labels, inputs=inputs),
                            compute_result=is_last_step,
                        )
                    else:
                        metrics = self.compute_metrics(
                            EvalPrediction(predictions=logits, label_ids=labels),
                            compute_result=is_last_step,
                        )

                del losses, logits, labels, inputs

This is due to the fact that, when packing is False, the labels are not kept in the input tensor, thus loss and labels after the prediction steps are None. And here the code crashes because losses is not defined.
UnboundLocalError: local variable 'losses' referenced before assignment
Is there something I'm missing to make it work properly?

Using transformers==4.41.2


Update
With transformers==4.42.4 this problem is solved. Although, in the same code snippet I shared, labels is still None, thus the compute_metrics function is not called.
This is happening because input doesn't have labels in it from the eval_dataset, if eval_packing is False.

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.

[FEATURE REQUEST] Allow setting packing=True for training but =False for evaluation in the same trainer
4 participants