MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / tensor_size

Function tensor_size

src/transformers/src/transformers/utils/generic.py:694–709  ·  view source on GitHub ↗

Framework-agnostic version of `numpy.size` that will work on torch/TensorFlow/Jax tensors as well as NumPy arrays.

(array)

Source from the content-addressed store, hash-verified

692
693
694def tensor_size(array):
695 """
696 Framework-agnostic version of `numpy.size` that will work on torch/TensorFlow/Jax tensors as well as NumPy arrays.
697 """
698 if is_numpy_array(array):
699 return np.size(array)
700 elif is_torch_tensor(array):
701 return array.numel()
702 elif is_tf_tensor(array):
703 import tensorflow as tf
704
705 return tf.size(array)
706 elif is_jax_tensor(array):
707 return array.size
708 else:
709 raise ValueError(f"Type not supported for tensor_size: {type(array)}.")
710
711
712def add_model_info_to_auto_map(auto_map, repo_id):

Callers 1

Calls 5

is_numpy_arrayFunction · 0.85
is_torch_tensorFunction · 0.85
is_tf_tensorFunction · 0.85
is_jax_tensorFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected