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

Method __new__

deepspeed/compile/patch_compiled_func.py:29–50  ·  view source on GitHub ↗
(cls, name, bases, dct)

Source from the content-addressed store, hash-verified

27 class FunctionMeta(base_meta):
28
29 def __new__(cls, name, bases, dct):
30 if name == "CompiledFunction":
31 original_backward_impl = _unwrap_staticmethod(dct.get("_backward_impl"))
32 frame_key = backward_frame_keys.popleft() if backward_frame_keys else None
33
34 def wrapped_backward_impl(ctx, all_args):
35 assert original_backward_impl is not None
36
37 if enabled_patched_func and frame_key is not None:
38 backward_inputs.setdefault(frame_key, []).append(all_args)
39 wrapped_backward_impl.owner_class.compiled_bw = None
40
41 return original_backward_impl(ctx, all_args)
42
43 wrapped_backward_impl.owner_class = None
44 dct["_backward_impl"] = staticmethod(wrapped_backward_impl)
45 new_class = super().__new__(cls, name, bases, dct)
46 wrapped_backward_impl.owner_class = new_class
47
48 return new_class
49
50 return super().__new__(cls, name, bases, dct)
51
52elif required_torch_version(min_version=2.6):
53

Callers

nothing calls this directly

Calls 2

_unwrap_staticmethodFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected