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

Method get_seq_length

deepspeed/utils/static_cache.py:145–157  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

143 return self._write_position
144
145 def get_seq_length(self) -> int | torch.Tensor:
146 # Transformers >= 5.20 cache protocol (#8852): the length counts the
147 # slot the current query is writing, so it is one past the write
148 # position; position/mask math must use get_query_offset() instead
149 # (it returns the write position itself). Our decode paths pass
150 # cache_position/position_ids explicitly, so this value never feeds
151 # RoPE. Kept as a tensor expression: this is read inside captured
152 # regions and must not sync.
153 if not self.is_initialized:
154 return 0
155 if self._write_position is not None:
156 return self._write_position + 1
157 return 0
158
159 def get_max_cache_shape(self) -> int:
160 return self.max_cache_len

Calls

no outgoing calls