MCPcopy Create free account
hub / github.com/modelscope/FunASR / maybe_autocast

Function maybe_autocast

funasr/train_utils/trainer.py:25–36  ·  view source on GitHub ↗

Context manager for mixed precision training. Args: enabled: Whether to enable autocast. dtype: torch.float16 or torch.bfloat16. If None, defaults to float16.

(enabled, dtype=None)

Source from the content-addressed store, hash-verified

23
24@contextmanager
25def maybe_autocast(enabled, dtype=None):
26 """Context manager for mixed precision training.
27
28 Args:
29 enabled: Whether to enable autocast.
30 dtype: torch.float16 or torch.bfloat16. If None, defaults to float16.
31 """
32 if enabled:
33 with autocast(dtype=dtype):
34 yield
35 else:
36 yield
37
38
39class Trainer:

Callers 1

train_epochMethod · 0.70

Calls 1

autocastFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…