MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / pack_dict_to_tensor

Function pack_dict_to_tensor

bitsandbytes/utils.py:166–180  ·  view source on GitHub ↗

Pack a dictionary into a torch tensor for storing quant_state items in state_dict. Parameters: - source_dict: The dictionary to be packed. Returns: A torch tensor containing the packed data.

(source_dict)

Source from the content-addressed store, hash-verified

164
165
166def pack_dict_to_tensor(source_dict):
167 """
168 Pack a dictionary into a torch tensor for storing quant_state items in state_dict.
169
170 Parameters:
171 - source_dict: The dictionary to be packed.
172
173 Returns:
174 A torch tensor containing the packed data.
175 """
176 json_str = json.dumps(source_dict)
177 json_bytes = json_str.encode("utf-8")
178 tensor_data = torch.tensor(list(json_bytes), dtype=torch.uint8)
179
180 return tensor_data
181
182
183def unpack_tensor_to_dict(tensor_data):

Callers 1

as_dictMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected