| 228 | |
| 229 | |
| 230 | def _get_tensor_bytes( |
| 231 | tensor: Tensor, |
| 232 | constant_buffer: list, |
| 233 | mutable_data: Optional[list], |
| 234 | ) -> Optional[bytes]: |
| 235 | if tensor.data_buffer_idx > 0 and tensor.data_buffer_idx < len(constant_buffer): |
| 236 | return constant_buffer[tensor.data_buffer_idx].storage |
| 237 | if ( |
| 238 | tensor.extra_tensor_info |
| 239 | and tensor.extra_tensor_info.mutable_data_segments_idx > 0 |
| 240 | and mutable_data is not None |
| 241 | and tensor.extra_tensor_info.mutable_data_segments_idx < len(mutable_data) |
| 242 | ): |
| 243 | return mutable_data[tensor.extra_tensor_info.mutable_data_segments_idx].storage |
| 244 | return None |
| 245 | |
| 246 | |
| 247 | def _unravel_index(flat_idx: int, sizes: List[int]) -> Tuple[int, ...]: |