Repository: pytorch
Issue: Torch 2.5.0 vs 2.4.1: torch nested in BetterTransformer fastpath implementation
Labels: needs reproduction,triaged,module: nestedtensor,oncall: pt2

### 🐛 Describe the bug

Thanks for the new torch release! 

I am using torch nested in the bettertransfromer implementation. https://pytorch.org/blog/a-better-transformer-for-fast-transformer-encoder-inference/

Here is the exact code where torch compile breaks:
https://github.com/huggingface/optimum/blob/1e5014e70f17e0437c4b0a7f4e65e170688d8ab0/optimum/bettertransformer/models/encoder_models.py#L203 and
https://github.com/huggingface/optimum/blob/1e5014e70f17e0437c4b0a7f4e65e170688d8ab0/optimum/bettertransformer/models/encoder_models.py#L146

```
/home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py:725: UserWarning: Graph break due to unsupported builtin torch._VariableFunctionsClass._nested_tensor_from_mask. This function is either a Python builtin (e.g. _warnings.warn) or a third-party C/C++ Python extension (perhaps created with pybind). If it is a Python builtin, please file an issue on GitHub so the PyTorch team can add support for it and see the next case for a workaround. If it is a third-party C/C++ Python extension, please either wrap it into a PyTorch-understood custom operator (see https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html for more details) or, if it is traceable, use torch.compiler.allow_in_graph.
  torch._dynamo.utils.warn_once(msg)
/home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/optimum/bettertransformer/models/encoder_models.py:301: UserWarning: The PyTorch API of nested tensors is in prototype stage and will change in the near future. (Triggered internally at ../aten/src/ATen/NestedTensorImpl.cpp:178.)
  hidden_states = torch._nested_tensor_from_mask(hidden_states, ~attention_mask)
terminate called after throwing an instance of 'c10::Error'
  what():  Internal error: NestedTensorImpl doesn't support strides. Please file an issue.
Exception raised from sym_strides_custom at ../aten/src/ATen/NestedTensorImpl.cpp:285 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x7fa5cf6b9446 in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libc10.so)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*) + 0x68 (0x7fa5cf6637ad in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libc10.so)
frame #2: <unknown function> + 0x1887313 (0x7fa5babf4313 in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #3: torch::dynamo::TensorCheck::check(torch::dynamo::LocalState const&, at::Tensor const&) + 0x434 (0x7fa5ce897994 in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so)
frame #4: <unknown function> + 0x8ebc7d (0x7fa5ce88bc7d in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so)
frame #5: <unknown function> + 0x8ec46e (0x7fa5ce88c46e in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so)
frame #6: <unknown function> + 0x8e8430 (0x7fa5ce888430 in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so)
frame #7: <unknown function> + 0x8e6cf6 (0x7fa5ce886cf6 in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so)
frame #8: <unknown function> + 0x16b3ce (0x55dd1371c3ce in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #9: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #10: <unknown function> + 0x16b3ce (0x55dd1371c3ce in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #11: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #12: _PyObject_FastCallDictTstate + 0xc4 (0x55dd13703474 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #13: _PyObject_Call_Prepend + 0xc1 (0x55dd13719321 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #14: <unknown function> + 0x2826d0 (0x55dd138336d0 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #15: _PyObject_MakeTpCall + 0x25b (0x55dd137042db in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #16: _PyEval_EvalFrameDefault + 0x64d6 (0x55dd136fc6e6 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #17: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #18: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #19: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #20: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #21: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #22: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #23: _PyFunction_Vectorcall + 0x7c (0x55dd1370e42c in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #24: _PyObject_FastCallDictTstate + 0x16d (0x55dd1370351d in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #25: _PyObject_Call_Prepend + 0x5c (0x55dd137192bc in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #26: <unknown function> + 0x2826d0 (0x55dd138336d0 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #27: _PyObject_MakeTpCall + 0x25b (0x55dd137042db in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #28: _PyEval_EvalFrameDefault + 0x72ea (0x55dd136fd4fa in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #29: <unknown function> + 0x8e6ebd (0x7fa5ce886ebd in /home/michael/infinity/libs/infinity_emb/.venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so)
frame #30: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #31: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #32: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #33: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #34: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #35: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #36: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #37: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #38: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #39: _PyFunction_Vectorcall + 0x7c (0x55dd1370e42c in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #40: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #41: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #42: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #43: PyObject_Call + 0x122 (0x55dd1371cf22 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #44: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #45: _PyFunction_Vectorcall + 0x7c (0x55dd1370e42c in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #46: _PyObject_FastCallDictTstate + 0x16d (0x55dd1370351d in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #47: _PyObject_Call_Prepend + 0x5c (0x55dd137192bc in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #48: <unknown function> + 0x2826d0 (0x55dd138336d0 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #49: PyObject_Call + 0xbb (0x55dd1371cebb in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #50: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #51: <unknown function> + 0x16b3ce (0x55dd1371c3ce in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #52: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #53: <unknown function> + 0x16b3ce (0x55dd1371c3ce in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #54: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #55: _PyObject_FastCallDictTstate + 0xc4 (0x55dd13703474 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #56: _PyObject_Call_Prepend + 0x5c (0x55dd137192bc in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #57: <unknown function> + 0x2826d0 (0x55dd138336d0 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #58: PyObject_Call + 0xbb (0x55dd1371cebb in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #59: _PyEval_EvalFrameDefault + 0x285e (0x55dd136f8a6e in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #60: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #61: _PyEval_EvalFrameDefault + 0x613a (0x55dd136fc34a in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
frame #62: <unknown function> + 0x16b281 (0x55dd1371c281 in /home/michael/infinity/libs/infinity_emb/.venv/bin/python)
```


### Versions

Torch=2.5.0
Torch=2.4.1

cc @cpuhrsch @jbschlosser @bhosmer @drisspg @soulitzer @davidberard98 @YuqingJ @ezyang @chauhang @penguinwu