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

Method __call__

deepspeed/runtime/hybrid_engine_graph.py:150–180  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

148 return self._forward(*args, **kwargs)
149
150 def __call__(self, *args, **kwargs):
151 input_ids = kwargs.get("input_ids")
152 is_decode_step = (input_ids is not None and input_ids.dim() == 2 and input_ids.shape[1] == 1)
153
154 if not self._use_graphs or not is_decode_step:
155 return self._forward(*args, **kwargs)
156
157 position = self._position
158 self._position += 1
159
160 if position >= self._max_positions:
161 # begin_sequence() bounds the length, so this means the caller ran
162 # longer than it declared. Replays have already happened, so eager
163 # execution would read a stale sequence counter.
164 raise RuntimeError(f"HybridEngine graph capture: generation exceeded the declared length "
165 f"({self._max_positions} decode steps). Set hybrid_engine.max_out_tokens "
166 f"to cover the longest generation, or disable hybrid_engine.enable_graph_capture.")
167
168 if position in self._graphs:
169 if self._shapes_match(position, kwargs):
170 return self._replay(position, kwargs)
171 return self._fall_back("input shapes changed mid-sequence", args, kwargs)
172
173 try:
174 self._capture(position, args, kwargs)
175 except Exception as err:
176 return self._fall_back(f"capture failed at position {position}: {err}", args, kwargs)
177
178 # Capture records the work without running it, so the first execution must
179 # come from a replay. That is also what fills the KV cache for this position.
180 return self._replay(position, kwargs)
181
182
183def decode_steps_from_generate_kwargs(kwargs):

Callers

nothing calls this directly

Calls 6

_shapes_matchMethod · 0.95
_replayMethod · 0.95
_fall_backMethod · 0.95
_captureMethod · 0.95
getMethod · 0.45
_forwardMethod · 0.45

Tested by

no test coverage detected