How to solve TracerWarning during onnx export

Hello !

My question is very simple: The first 3 lines of my forward are these:

    def forward(self, x):
        h, w = x.shape[2:]
        max_offset = max(h, w) / 4.

Everything works fine during training and evaluation. When I want to export my model in onnx format I get this warning :

TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  max_offset = max(h, w) / 4.

I understand that the max_offset value will be calculated once during export and then stored as a constant value. But how can I make the value dynamic?

I’ve been stuck on this point for hours…

Thanks in advance

I’ve edited your title and removed the expletive so please watch your language in future posts.

You’re right. Sorry about that… After several hours of being stuck, frustration mounts…