| 60 | transport_stream = None |
| 61 | cuda_device=None |
| 62 | def detach_variable(inputs, device=None): |
| 63 | if isinstance(inputs, tuple): |
| 64 | out = [] |
| 65 | for inp in inputs: |
| 66 | if not isinstance(inp, torch.Tensor): |
| 67 | out.append(inp) |
| 68 | continue |
| 69 | |
| 70 | requires_grad = inp.requires_grad |
| 71 | |
| 72 | if device is not None: |
| 73 | x = inp.to(device=device) |
| 74 | else: |
| 75 | x = inp |
| 76 | |
| 77 | x = x.detach() |
| 78 | x.requires_grad = requires_grad |
| 79 | out.append(x) |
| 80 | return tuple(out) |
| 81 | else: |
| 82 | raise RuntimeError( |
| 83 | "Only tuple of tensors is supported. Got Unsupported input type: ", type(inputs).__name__) |
| 84 | |
| 85 | def _set_cuda_rng_state(new_state, device=-1): |
| 86 | """Sets the random number generator state of the current GPU. |