Skip to content

Commit 1d9f0f2

Browse files
committed
add QuantState.__get_item__() for compatibility
1 parent 0a0b531 commit 1d9f0f2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

bitsandbytes/functional.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,20 @@ def __init__(self, absmax, shape=None, code=None, blocksize=None, quant_type=Non
579579
self.offset = offset
580580
self.state2 = state2
581581
self.nested = state2 is not None
582-
582+
583+
def __get_item__(self, idx):
584+
"""
585+
ensures compatibility with older quant state scheme with nested lists.
586+
assumes the following layout:
587+
state = [qabsmax, input_shape, A.dtype, blocksize, [offset, state2], quant_type]
588+
state2 = [absmax, input_shape, A.dtype, blocksize, None, quant_type]
589+
"""
590+
if self.nested:
591+
list_repr = [self.absmax, self.shape, self.dtype, self.blocksize, [self.offset, self.state2], self.quant_type]
592+
else:
593+
list_repr = [self.absmax, self.shape, self.dtype, self.blocksize, None, self.quant_type]
594+
return list_repr[idx]
595+
583596
@classmethod
584597
def from_dict(cls, qs_dict: dict[str, Any], device: torch.device) -> 'QuantState':
585598
"""

0 commit comments

Comments
 (0)