in optimum/quanto/tensor/weights/qbits.py [0:0]
def optimize(self):
"""Allows to convert an existing WeightQBitsTensor to an optimized subclass
This is used in particular after reloading a serialized WeightQBitsTensor (which is
always saved using the kernel-agnostic packing).
"""
if type(self) is not WeightQBitsTensor:
return self
data = self._data.unpack()
# Call dedicated helper to select the best subclass for this device
return WeightQBitsTensor.create(
self.qtype,
self.axis,
self._group_size,
self.size(),
self.stride(),
data,
self._scale,
self._shift,
self.requires_grad,
)