class_docstr: A compression strategy that applies mean-std scaling over last axis before casting to float16
class_docstr_tok: ["A","compression","strategy","that","applies","mean-std","scaling","over","last","axis","before","casting","to","float16"]
code: def extract(
      self, serialized_tensor: runtime_pb2.Tensor
  ) -> torch.Tensor:
      stats_shape = list(serialized_tensor.size)
      stats_shape[-1] = 1
      stats_count = np.prod(stats_shape)
      means_offset = (
          len(serialized_tensor.buffer)
          - 2 * stats_count * self.FP32_BYTES
      )
      stds_offset = (
          len(serialized_tensor.buffer) - stats_count * self.FP32_BYTES
      )
  
      array = np.frombuffer(
          serialized_tensor.buffer,
          dtype=np.float16,
          count=np.prod(serialized_tensor.size),
      )
      means = np.frombuffer(
          serialized_tensor.buffer,
          dtype=np.float32,
          offset=means_offset,
          count=stats_count,
      )
      stds = np.frombuffer(
          serialized_tensor.buffer,
          dtype=np.float32,
          offset=stds_offset,
          count=stats_count,
      )
  
      means = torch.as_tensor(means).reshape(stats_shape)
      stds = torch.as_tensor(stds).reshape(stats_shape)
      tensor = torch.as_tensor(
          np.asarray(array, dtype=serialized_tensor.dtype)
      ).reshape(list(serialized_tensor.size))
      dtype = getattr(torch, serialized_tensor.dtype)
      return (
          tensor.mul_(stds)
          .add_(means)
          .to(dtype)
          .requires_grad_(serialized_tensor.requires_grad)
      )
  
file_path: hivemind/hivemind/compression/floating.py
imports: import math
  import numpy
  import torch
  from hivemind.compression.base import CompressionBase, CompressionInfo
  from hivemind.proto import runtime_pb2
label_desc: Use image node_id 2 for calling the ScaledFloat16Compression obj's underlying member method code with example usage: obj.extract(serialized_tensor) and returns: tensor