MCPcopy Create free account
hub / github.com/eric-mitchell/direct-preference-optimization / clip_gradient

Method clip_gradient

trainers.py:397–399  ·  view source on GitHub ↗

Clip the gradient norm of the parameters of a non-FSDP policy.

(self)

Source from the content-addressed store, hash-verified

395
396
397 def clip_gradient(self):
398 """Clip the gradient norm of the parameters of a non-FSDP policy."""
399 return torch.nn.utils.clip_grad_norm_(self.policy.parameters(), self.config.max_grad_norm).item()
400
401 def write_state_dict(self, step: int, state: Dict[str, torch.Tensor], metrics: Dict, filename: str, dir_name: Optional[str] = None):
402 """Write a checkpoint to disk."""

Callers 1

trainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected