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

Function tensor_match_wrapper

deepspeed/compile/patch_fake_tensor.py:107–124  ·  view source on GitHub ↗
(self, guard, value=None)

Source from the content-addressed store, hash-verified

105
106 @wraps(original_tensor_match)
107 def tensor_match_wrapper(self, guard, value=None):
108 guarded_value = _resolve_zero3_guarded_value(self, guard, value)
109 if hasattr(guarded_value, "ds_id") and hasattr(guarded_value, "ds_shape"):
110 expected = _zero3_parameter_guard_metadata(guarded_value)
111
112 def semantic_parameter_guard(param):
113 return _matches_zero3_parameter_metadata(param, expected)
114
115 code = f"DeepCompile ZeRO-3 semantic parameter ds_id={expected[-2]} shape={expected[-1]}"
116 guard_manager = self.get_guard_manager(guard)
117 verbose_code = get_verbose_code_parts(code, guard)
118 try:
119 guard_manager.add_lambda_guard(semantic_parameter_guard, verbose_code, guard.user_stack)
120 except TypeError:
121 # PyTorch 2.10 does not yet accept the user stack argument.
122 guard_manager.add_lambda_guard(semantic_parameter_guard, verbose_code)
123 return
124 return original_tensor_match(self, guard, value)
125
126 GuardBuilder.TENSOR_MATCH = tensor_match_wrapper
127

Callers

nothing calls this directly

Calls 3

original_tensor_matchFunction · 0.85

Tested by

no test coverage detected