MCPcopy Create free account
hub / github.com/ChenhongyiYang/QueryDet-PyTorch / detach_variable

Function detach_variable

utils/gradient_checkpoint.py:6–20  ·  view source on GitHub ↗
(inputs: Tuple[Any, ...])

Source from the content-addressed store, hash-verified

4
5
6def detach_variable(inputs: Tuple[Any, ...]) -> Tuple[torch.Tensor, ...]:
7 if isinstance(inputs, tuple):
8 out = []
9 for inp in inputs:
10 if not isinstance(inp, torch.Tensor):
11 out.append(inp)
12 continue
13
14 x = inp.detach()
15 x.requires_grad = inp.requires_grad
16 out.append(x)
17 return tuple(out)
18 else:
19 raise RuntimeError(
20 "Only tuple of tensors is supported. Got Unsupported input type: ", type(inputs).__name__)
21
22
23def check_backward_validity(inputs: Iterable[Any]) -> None:

Callers 1

backwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected