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)
| 322 | |
| 323 | |
| 324 | def 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 | |
| 355 | def matmul_hadU(X: Tensor) -> paddle.Tensor: |
no test coverage detected