MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / convert

Function convert

convert-dense.py:544–569  ·  view source on GitHub ↗
(name: str)

Source from the content-addressed store, hash-verified

542 names = {name: None for model in models for name in model}
543
544 def convert(name: str) -> LazyTensor:
545 lazy_tensors: list[LazyTensor] = [model[name] for model in models]
546 if len(lazy_tensors) == 1:
547 # only one file; don't go through this procedure since there might
548 # be quantized tensors
549 return lazy_tensors[0]
550 if len(lazy_tensors[0].shape) == 1:
551 # the tensor is just duplicated in every file
552 return lazy_tensors[0]
553 if name.startswith('tok_embeddings.') or \
554 name.endswith('.attention.wo.weight') or \
555 name.endswith('.feed_forward.w2.weight'):
556 # split by columns
557 axis = 1
558 else:
559 # split by rows
560 axis = 0
561 concatenated_shape = list(lazy_tensors[0].shape)
562 concatenated_shape[axis] = sum(tensor.shape[axis] for tensor in lazy_tensors)
563
564 def load() -> UnquantizedTensor:
565 ndarrays = [load_unquantized(tensor) for tensor in lazy_tensors]
566 concatenated: NDArray = np.concatenate(ndarrays, axis=axis)
567 return UnquantizedTensor(concatenated)
568 description = 'concatenated[[' + '] | ['.join(lt.description for lt in lazy_tensors) + ']]'
569 return LazyTensor(load, concatenated_shape, lazy_tensors[0].data_type, description)
570 return {name: convert(name) for name in names}
571
572

Callers 2

merge_shardedFunction · 0.70

Calls 2

joinMethod · 0.80
LazyTensorClass · 0.70

Tested by

no test coverage detected