# Tensorboard issue with self-defined forward function

**URL:** <https://discuss.pytorch.org/t/tensorboard-issue-with-self-defined-forward-function/140628>\
**Category:** Uncategorized\
**Created:** [January 1, 2022, 3:44pm UTC](https://discuss.pytorch.org/t/tensorboard-issue-with-self-defined-forward-function/140628 "2022-01-01T15:44:43Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![promach](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/promach/32/22571_2.png) [@promach](https://discuss.pytorch.org/u/promach)\
**Post date:** [January 6, 2022, 3:40pm UTC](https://discuss.pytorch.org/t/tensorboard-issue-with-self-defined-forward-function/140628/5 "2022-01-06T15:40:10Z")

</div>

[This new code](https://gist.github.com/promach/b6f526c56e20f029d68e6f9041c3f5c0#file-gdas-py-L283) seems to have gotten around the self-defined forward function issue, but it has the following new error. Should I create a new question for this new issue ?

Should I use [add\_module()](https://discuss.pytorch.org/t/when-to-use-add-module-function/10534) instead of [nn.ModuleList()](https://gist.github.com/promach/b6f526c56e20f029d68e6f9041c3f5c0#file-gdas-py-L279) in this case ?

```auto
Error occurs, No graph saved
Traceback (most recent call last):
  File "/home/phung/PycharmProjects/beginner_tutorial/gdas.py", line 794, in <module>
    ltrain = train_NN(forward_pass_only=0)
  File "/home/phung/PycharmProjects/beginner_tutorial/gdas.py", line 551, in train_NN
    writer.add_graph(graph, NN_input)
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/utils/tensorboard/writer.py", line 736, in add_graph
    self._get_file_writer().add_graph(graph(model, input_to_model, verbose, use_strict_trace))
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/utils/tensorboard/_pytorch_graph.py", line 295, in graph
    raise e
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/utils/tensorboard/_pytorch_graph.py", line 289, in graph
    trace = torch.jit.trace(model, args, strict=use_strict_trace)
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/jit/_trace.py", line 741, in trace
    return trace_module(
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/jit/_trace.py", line 958, in trace_module
    module._c._create_method_from_trace(
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/phung/PycharmProjects/venv/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1090, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/phung/PycharmProjects/beginner_tutorial/gdas.py", line 322, in forward
    self.cells[c].nodes[n].connections[
RuntimeError: Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

```

---

_[View the full topic](https://discuss.pytorch.org/t/tensorboard-issue-with-self-defined-forward-function/140628)._
