MCPcopy Create free account
hub / github.com/microsoft/BitNet / write_tensor_data

Method write_tensor_data

utils/convert-ms-to-gguf-bitnet.py:1247–1277  ·  view source on GitHub ↗
(self, ftype: GGMLFileType, model: LazyModel, concurrency: int)

Source from the content-addressed store, hash-verified

1245 self.gguf.write_ti_data_to_file()
1246
1247 def write_tensor_data(self, ftype: GGMLFileType, model: LazyModel, concurrency: int) -> None:
1248 ndarrays_inner = bounded_parallel_map(OutputFile.do_item, model.items(), concurrency=concurrency)
1249 if ftype == GGMLFileType.MostlyQ8_0:
1250 ndarrays = bounded_parallel_map(
1251 OutputFile.maybe_do_quantize, ndarrays_inner, concurrency=concurrency, max_workers=concurrency,
1252 use_processpool_executor=True,
1253 )
1254 # elif ftype == GGMLFileType.MostlyI2:
1255 # # ndarrays = bounded_parallel_map(
1256 # # OutputFile.maybe_do_transform, ndarrays_inner, concurrency=concurrency, max_workers=concurrency, use_processpool_executor=True,)
1257 # ndarrays = map(OutputFile.maybe_do_transform, ndarrays_inner)
1258 else:
1259 ndarrays = map(OutputFile.maybe_do_quantize, ndarrays_inner)
1260
1261 start = time.time()
1262 for i, ((name, lazy_tensor), ndarray) in enumerate(zip(model.items(), ndarrays)):
1263 ndarray, i2_scale = ndarray
1264 elapsed = time.time() - start
1265 size = ' x '.join(f"{dim:6d}" for dim in lazy_tensor.shape)
1266 padi = len(str(len(model)))
1267 logger.info(
1268 f"[{i + 1:{padi}d}/{len(model)}] Writing tensor {name:38s} | size {size:16} | type {lazy_tensor.data_type.name:4} | T+{int(elapsed):4}"
1269 )
1270
1271 if i2_scale is not None:
1272 i2_scale = np.tile(i2_scale, 8)
1273 ndarray = preprocess_weights(ndarray)
1274 self.gguf.write_tensor_data(ndarray)
1275 self.gguf.write_tensor_data(i2_scale)
1276 else:
1277 self.gguf.write_tensor_data(ndarray)
1278
1279 def close(self) -> None:
1280 self.gguf.close()

Callers 1

write_allMethod · 0.95

Calls 2

bounded_parallel_mapFunction · 0.70
preprocess_weightsFunction · 0.70

Tested by

no test coverage detected