MCPcopy
hub / github.com/modelscope/FunASR / to_device

Function to_device

funasr/models/transformer/utils/nets_utils.py:12–29  ·  view source on GitHub ↗

Send tensor into the device of the module. Args: m (torch.nn.Module): Torch module. x (Tensor): Torch tensor. Returns: Tensor: Torch tensor located in the same place as torch module.

(m, x)

Source from the content-addressed store, hash-verified

10
11
12def to_device(m, x):
13 """Send tensor into the device of the module.
14
15 Args:
16 m (torch.nn.Module): Torch module.
17 x (Tensor): Torch tensor.
18
19 Returns:
20 Tensor: Torch tensor located in the same place as torch module.
21
22 """
23 if isinstance(m, torch.nn.Module):
24 device = next(m.parameters()).device
25 elif isinstance(m, torch.Tensor):
26 device = m.device
27 else:
28 raise TypeError("Expected torch.nn.Module or torch.tensor, " f"bot got: {type(m)}")
29 return x.to(device)
30
31
32def pad_list(xs, pad_value):

Callers 15

forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90

Calls 1

parametersMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…