# Mark\_dynamic does not work when the dimension is 1

**URL:** <https://discuss.pytorch.org/t/mark-dynamic-does-not-work-when-the-dimension-is-1/224544>\
**Category:** torch.compile\
**Created:** [February 12, 2026, 7:19pm UTC](https://discuss.pytorch.org/t/mark-dynamic-does-not-work-when-the-dimension-is-1/224544 "2026-02-12T19:19:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmaeng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kmaeng/32/23707_2.png) [@kmaeng](https://discuss.pytorch.org/u/kmaeng)\
**Post date:** [February 12, 2026, 7:19pm UTC](https://discuss.pytorch.org/t/mark-dynamic-does-not-work-when-the-dimension-is-1/224544/1 "2026-02-12T19:19:49Z")

</div>

Dear experts. I am trying to use torch.compile and avoid recompiling due to dynamic shapes, but it always seem to cause recompile when the dynamic dimension happens to be 1. Below is my minimal repro code:

```auto
import torch
@torch.compile
def f(x):
  return x.sum()

x = torch.rand([4, 2, 2, 2])
#torch._dynamo.decorators.mark_unbacked(x, 0) # This works
#torch._dynamo.mark_dynamic(x, 0) # This doesn't work
torch._dynamo.mark_dynamic(x, 0, min=1, max=4) # This doesn't work either
f(x)
f(torch.rand([1, 2, 2, 2])) # This line causes recompile!
#f(torch.rand([2, 2, 2, 2])) # If I do this instead (2 instead of 1 in the 0-dim), it works nicely

```

Normally, calling `torch._dynamo.mark_dynamic(x, 0)` would work nicely, when the 0-th dimension changes and is always larger than or equal to 2.  
However, when the dimension changes to 1, it causes recompile. Using `mark_dynamic()` with explicitly setting the min=1 doesn’t work either.  
The only way I found to be working is to set `torch._dynamo.decorators.mark_unbacked(x, 0)`. From the document, I wasn’t sure what this actually does, but it seemed like this is not very recommended (here: [https://docs.pytorch.org/docs/stable/user\_guide/torch\_compiler/torch.compiler\_dynamic\_shapes.html#mark-unbacked-tensor-dim](https://docs.pytorch.org/docs/stable/user_guide/torch_compiler/torch.compiler_dynamic_shapes.html#mark-unbacked-tensor-dim)).

Is this a bug, or a known issue? What is the recommended fix? mark\_unbacked, or shall I rewrite my code so that the dimension size value is never 1, or is there some other way out?  
Thank you for any suggestions!

---

<div class="post-metadata">

**Author:** ![fairhills](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fairhills/32/79412_2.png) [@fairhills](https://discuss.pytorch.org/u/fairhills)\
**Post date:** [March 18, 2026, 2:35pm UTC](https://discuss.pytorch.org/t/mark-dynamic-does-not-work-when-the-dimension-is-1/224544/2 "2026-03-18T14:35:00Z")

</div>

This is expected. Value `1` is special, and it represents the broadcast dimension. Even if you set the range to `[1,4]`, the actual guard is still ` 2 <= x.size()[0] <= 4`

You can get more details with `TORCH_LOGS=recompiles`, you may get something like:

```auto
user code shown is first use of this value--the guard itself is not due user code but due to 0/1 specialization in the framework; to avoid specialization try torch._dynamo.decorators.mark_unbacked(tensor, dim))

```
