MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / get_tensor

Function get_tensor

fastdeploy/model_executor/layers/utils.py:324–352  ·  view source on GitHub ↗

Return a corresponding PaddlePaddle tensor based on the type and content of the input. Args: input (Union[paddle.Tensor, np.ndarray, str]): The input data. Returns: paddle.Tensor: Returns a PaddlePaddle tensor.

(input: Union[paddle.Tensor, np.ndarray, str], model_path=None)

Source from the content-addressed store, hash-verified

322
323
324def get_tensor(input: Union[paddle.Tensor, np.ndarray, str], model_path=None) -> paddle.Tensor:
325 """
326 Return a corresponding PaddlePaddle tensor based on the type and content of the input.
327
328 Args:
329 input (Union[paddle.Tensor, np.ndarray, str]): The input data.
330
331 Returns:
332 paddle.Tensor: Returns a PaddlePaddle tensor.
333
334 """
335 if "PySafeSlice" in str(type(input)):
336 input = input.get()
337
338 if isinstance(input, paddle.Tensor):
339 if input.place.is_cpu_place():
340 if current_platform.is_cuda():
341 return input.cuda()
342 else:
343 return input.to(paddle.device.get_device())
344 return input
345 elif isinstance(input, np.ndarray):
346 return paddle.to_tensor(input)
347 elif isinstance(input, str):
348 from fastdeploy.model_executor.load_weight_utils import load_reordered_experts
349
350 return load_reordered_experts(model_path, input)
351 else:
352 return input
353
354
355def matmul_hadU(X: Tensor) -> paddle.Tensor:

Callers 15

fnFunction · 0.90
h2d_copyFunction · 0.90
load_state_dictMethod · 0.90
weight_loaderMethod · 0.90
load_zpMethod · 0.90
load_scaleMethod · 0.90
load_scaleMethod · 0.90
weight_loaderMethod · 0.90
_extract_scale_tensorMethod · 0.90
load_zpMethod · 0.90

Calls 3

load_reordered_expertsFunction · 0.90
getMethod · 0.45
is_cudaMethod · 0.45

Tested by

no test coverage detected