MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / enable

Function enable

deepspeed/runtime/compiler.py:58–97  ·  view source on GitHub ↗

Decorator factory to enable compiling of a function if the minimum PyTorch version requirement is met. Args: min_version (str, optional): Minimum PyTorch version required (e.g., "2.7.0"). If None, the function is always enabled. Returns: Callable: A decorat

(min_version=None)

Source from the content-addressed store, hash-verified

56
57
58def enable(min_version=None):
59 """
60 Decorator factory to enable compiling of a function if the minimum PyTorch version requirement is met.
61
62 Args:
63 min_version (str, optional): Minimum PyTorch version required (e.g., "2.7.0").
64 If None, the function is always enabled.
65
66 Returns:
67 Callable: A decorator that wraps the function.
68
69 Examples:
70 @enable("2.7.0")
71 def my_function():
72 pass
73
74 @enable
75 def another_function():
76 pass
77 """
78
79 def decorator(func):
80 if not is_compiling():
81 return func
82
83 @functools.wraps(func)
84 def wrapper(*args, **kwargs):
85 if min_version is None or required_torch_version(min_version=min_version):
86 return func(*args, **kwargs)
87 return disable(func)(*args, **kwargs)
88
89 return wrapper
90
91 # Called with no arguments
92 if callable(min_version):
93 func = min_version
94 min_version = None
95 return decorator(func)
96
97 return decorator
98
99
100def is_compiling():

Callers 3

MaskMethod · 0.50
MaskMethod · 0.50
MaskMethod · 0.50

Calls 1

decoratorFunction · 0.70

Tested by

no test coverage detected