Fix GRPOTrainer evaluate() crash without prior training (#6523)
* Fix GRPOTrainer evaluate() crash when called without prior training GRPOTrainer.compute_loss read self.current_gradient_accumulation_steps directly. That attribute is only set by the transformers training loop, so calling trainer.evaluate() standalone (no prior trainer.train()) raised AttributeError. Read it via getattr with a fallback to args.gradient_accumulation_steps so standalone evaluation works. * GRPO eval: fall back accumulation steps to 1 so standalone eval_loss is not underreported * Tighten code comments (no logic change)
This commit is contained in:
parent
eae59b25b6
commit
f74c48eb58
1 changed files with 5 additions and 1 deletions
|
|
@ -1530,7 +1530,11 @@ def grpo_trainer_compute_loss(function_name, function):
|
|||
num_items_in_batch = inputs.get("num_items_in_batch", None)
|
||||
sampling_per_token_logps = inputs.get("sampling_per_token_logps", None)
|
||||
tool_mask = inputs.get("tool_mask", None)
|
||||
current_gradient_accumulation_steps = self.current_gradient_accumulation_steps
|
||||
# Missing when evaluate() runs standalone; eval does not accumulate, so
|
||||
# fall back to 1 to avoid underreporting eval_loss (#2464).
|
||||
current_gradient_accumulation_steps = getattr(
|
||||
self, "current_gradient_accumulation_steps", 1
|
||||
)
|
||||
num_processes = self.accelerator.num_processes
|
||||
|
||||
input_ids = torch.cat([prompt_ids, completion_ids], dim = 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue