MCPcopy Index your code
hub / github.com/microsoft/BitNet / convert

Function convert

utils/convert.py:872–897  ·  view source on GitHub ↗
(name: str)

Source from the content-addressed store, hash-verified

870 names = {name: None for model in models for name in model}
871
872 def convert(name: str) -> LazyTensor:
873 lazy_tensors = [model[name] for model in models]
874 if len(lazy_tensors) == 1:
875 # only one file; don't go through this procedure since there might
876 # be quantized tensors
877 return lazy_tensors[0]
878 if len(lazy_tensors[0].shape) == 1:
879 # the tensor is just duplicated in every file
880 return lazy_tensors[0]
881 if name.startswith('tok_embeddings.') or \
882 name.endswith('.attention.wo.weight') or \
883 name.endswith('.feed_forward.w2.weight'):
884 # split by columns
885 axis = 1
886 else:
887 # split by rows
888 axis = 0
889 concatenated_shape = list(lazy_tensors[0].shape)
890 concatenated_shape[axis] = sum(tensor.shape[axis] for tensor in lazy_tensors)
891
892 def load() -> UnquantizedTensor:
893 ndarrays = [load_unquantized(tensor) for tensor in lazy_tensors]
894 concatenated = np.concatenate(ndarrays, axis=axis)
895 return UnquantizedTensor(concatenated)
896 description = 'concatenated[[' + '] | ['.join(lt.description for lt in lazy_tensors) + ']]'
897 return LazyTensor(load, concatenated_shape, lazy_tensors[0].data_type, description)
898 return {name: convert(name) for name in names}
899
900

Callers 2

merge_shardedFunction · 0.70

Calls 1

LazyTensorClass · 0.70

Tested by

no test coverage detected