(self, *args, **kwargs)
| 242 | return self._trace.without_host |
| 243 | |
| 244 | def flatten_inputs(self, *args, **kwargs): |
| 245 | from ..traced_module.pytree import tree_flatten, SUPPORTED_LEAF_CLS |
| 246 | from ..module import Module |
| 247 | from ..optimizer import Optimizer |
| 248 | |
| 249 | if Optimizer not in SUPPORTED_LEAF_CLS: |
| 250 | SUPPORTED_LEAF_CLS.append(Optimizer) |
| 251 | |
| 252 | tensor_args = [] |
| 253 | modules = [] |
| 254 | fargs, _ = tree_flatten((args, kwargs)) |
| 255 | for a in fargs: |
| 256 | if isinstance(a, RawTensor): |
| 257 | tensor_args.append(a) |
| 258 | elif isinstance(a, Module): |
| 259 | modules.append(a) |
| 260 | elif isinstance(a, Optimizer): |
| 261 | states = a._state.values() |
| 262 | for s in states: |
| 263 | assert isinstance(s, dict) |
| 264 | tensor_args.extend(list(s.values())) |
| 265 | for m in modules: |
| 266 | tensor_args.extend(list(m.parameters())) |
| 267 | grads = [] |
| 268 | for t in tensor_args: |
| 269 | if t.grad is not None: |
| 270 | grads.append(t.grad) |
| 271 | for m in modules: |
| 272 | tensor_args.extend(list(m.buffers())) |
| 273 | tensor_args.extend(grads) |
| 274 | return tensor_args |
| 275 | |
| 276 | def compile(self): |
| 277 | raise NotImplementedError |
no test coverage detected