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

Function convert

convert.py:573–598  ·  view source on GitHub ↗
(name: str)

Source from the content-addressed store, hash-verified

571 names = {name: None for model in models for name in model}
572
573 def convert(name: str) -> LazyTensor:
574 lazy_tensors: list[LazyTensor] = [model[name] for model in models]
575 if len(lazy_tensors) == 1:
576 # only one file; don't go through this procedure since there might
577 # be quantized tensors
578 return lazy_tensors[0]
579 if len(lazy_tensors[0].shape) == 1:
580 # the tensor is just duplicated in every file
581 return lazy_tensors[0]
582 if name.startswith('tok_embeddings.') or \
583 name.endswith('.attention.wo.weight') or \
584 name.endswith('.feed_forward.w2.weight'):
585 # split by columns
586 axis = 1
587 else:
588 # split by rows
589 axis = 0
590 concatenated_shape = list(lazy_tensors[0].shape)
591 concatenated_shape[axis] = sum(tensor.shape[axis] for tensor in lazy_tensors)
592
593 def load() -> UnquantizedTensor:
594 ndarrays = [load_unquantized(tensor) for tensor in lazy_tensors]
595 concatenated: NDArray = np.concatenate(ndarrays, axis=axis)
596 return UnquantizedTensor(concatenated)
597 description = 'concatenated[[' + '] | ['.join(lt.description for lt in lazy_tensors) + ']]'
598 return LazyTensor(load, concatenated_shape, lazy_tensors[0].data_type, description)
599 return {name: convert(name) for name in names}
600
601

Callers 2

merge_shardedFunction · 0.70

Calls 2

joinMethod · 0.80
LazyTensorClass · 0.70

Tested by

no test coverage detected