| 211 | def _buffer_view(buf: torch.Tensor, dtype: torch.dtype, shape: tuple[int, ...]) -> torch.Tensor: |
| 212 | view = torch.empty(0, dtype=dtype, device=buf.device) |
| 213 | view.set_(buf.untyped_storage(), 0, shape) |
| 214 | return view |
| 215 | |
| 216 | def _sha256_tensor(tensor: Optional[torch.Tensor]) -> Optional[str]: |
| 217 | if tensor is None: |
| 218 | return None |
| 219 | data_tensor = tensor.detach() |
| 220 | if data_tensor.dtype == torch.bfloat16: |
| 221 | data_tensor = data_tensor.to(torch.float32) |
| 222 | data = data_tensor.contiguous().cpu().numpy().tobytes() |
| 223 | return hashlib.sha256(data).hexdigest() |