MCPcopy
hub / github.com/huggingface/transformers / compute_loss_context_manager

Method compute_loss_context_manager

src/transformers/trainer.py:2036–2046  ·  view source on GitHub ↗

A helper wrapper to group together context managers.

(self)

Source from the content-addressed store, hash-verified

2034 return (loss, outputs) if return_outputs else loss
2035
2036 def compute_loss_context_manager(self) -> contextlib.ExitStack:
2037 """
2038 A helper wrapper to group together context managers.
2039 """
2040 ctx_stack = contextlib.ExitStack()
2041
2042 autocast_ctx = self.autocast_smart_context_manager()
2043 if not isinstance(autocast_ctx, contextlib.nullcontext):
2044 ctx_stack.enter_context(autocast_ctx)
2045
2046 return ctx_stack
2047
2048 def autocast_smart_context_manager(self, cache_enabled: bool | None = True) -> contextlib.AbstractContextManager:
2049 """

Callers 3

training_stepMethod · 0.95
prediction_stepMethod · 0.95
prediction_stepMethod · 0.80

Calls 1

Tested by

no test coverage detected