# Tensorboard add\_graph (actually jit.trace) does not work with None inputs

**URL:** <https://discuss.pytorch.org/t/tensorboard-add-graph-actually-jit-trace-does-not-work-with-none-inputs/219863>\
**Category:** tensorboard\
**Created:** [May 8, 2025, 9:44am UTC](https://discuss.pytorch.org/t/tensorboard-add-graph-actually-jit-trace-does-not-work-with-none-inputs/219863 "2025-05-08T09:44:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![turbotimon](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/turbotimon/32/69503_2.png) [@turbotimon](https://discuss.pytorch.org/u/turbotimon)\
**Post date:** [May 8, 2025, 9:44am UTC](https://discuss.pytorch.org/t/tensorboard-add-graph-actually-jit-trace-does-not-work-with-none-inputs/219863/1 "2025-05-08T09:44:13Z")

</div>

Hi, I have a problem where a forward method takes optional inputs:

```python
def forward(self, x_in):
    x1, x2 = x_in
   if x2 is None:
     ...

```

so when I want to `add_graph` for a case without the x2 provided…

```python
writer.add_graph(model, input_to_model=((x, None)))

```

… I get an error:

```sh
"**/jit/_trace.py", line 1278, in trace_module
    module._c._create_method_from_trace(
RuntimeError: Type 'Tuple[Tensor, NoneType]' cannot be traced. Only Tensors and (possibly nested) Lists, Dicts, and Tuples of Tensors can be traced

```

Is there an easy workaround?

- changing the signature of `forward` is not an option
- in this simple example, also providing x2 would not hurt, but the real example is more complex, resulting in another graph

Thanks in advance

* * *

(Minimal reproducible example on request available)

---

<div class="post-metadata">

**Author:** ![turbotimon](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/turbotimon/32/69503_2.png) [@turbotimon](https://discuss.pytorch.org/u/turbotimon)\
**Post date:** [May 8, 2025, 9:52am UTC](https://discuss.pytorch.org/t/tensorboard-add-graph-actually-jit-trace-does-not-work-with-none-inputs/219863/2 "2025-05-08T09:52:55Z")

</div>

btw: I found out there is an open request for something similar, but its open since a while… [Allow tracing of models which output `None` · Issue #18850 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/18850)

the only solution I came up with, is either wrapping or monkey-patching the forward method of the model to not take a tuple but optional arguments…
