Skip to content

Add version linter for files in torch/csrc/stable that use torch/csrc/stable/c/shim.h - #166996

Closed
mikaylagawarecki wants to merge 15 commits into
gh/mikaylagawarecki/363/basefrom
gh/mikaylagawarecki/363/head
Closed

mikaylagawarecki wants to merge 15 commits into
gh/mikaylagawarecki/363/basefrom
gh/mikaylagawarecki/363/head

Conversation

@mikaylagawarecki

@mikaylagawarecki mikaylagawarecki commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

This PR ensures that files in torch/csrc/stable that include from torch/csrc/stable/shim.h properly gate calls to the stable shim APIs with the appropriate TORCH_FEATURE_VERSION macros

Examples

  1. Commenting out the version guard in

#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
"aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
TORCH_ERROR_CODE_CHECK(
aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif

Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
  1. Changing the first line to say #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0

Doesn't error because this is still valid!

  1. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
   Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
   this function requires at least TORCH_VERSION_2_10_0. The version guard
   must be at least the required version:
   #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
     // ... your code calling torch_call_dispatcher ...
   #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

       263  |      torch::stable::detail::from(self),
       264  |      torch::stable::detail::from(std::nullopt)};
       265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
   >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
       267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
       268  |#else
       269  |  TORCH_ERROR_CODE_CHECK(
       
  1. Nested ifdefs
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif

No error!

Stack from ghstack (oldest at bottom):

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Nov 4, 2025
@pytorch-bot

pytorch-bot Bot commented Nov 4, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/166996

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 1 Cancelled Job

As of commit 596a242 with merge base 3f09374 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

…e/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros




[ghstack-poisoned]
@mikaylagawarecki mikaylagawarecki mentioned this pull request Nov 4, 2025
mikaylagawarecki added a commit that referenced this pull request Nov 4, 2025
…e/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Nov 4, 2025
…e/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
…e/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Nov 6, 2025
…e/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Nov 6, 2025
@mikaylagawarecki
mikaylagawarecki marked this pull request as ready for review November 6, 2025 21:01

@janeyx99 janeyx99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nits + requests for clarity, but overall looks good! thanks for the tests and example files

def __init__(self):
"""Initialize the preprocessor tracker."""
# Stack of (is_version_block, version_tuple) tuples
# is_version_block: True if this is a TORCH_FEATURE_VERSION >= TORCH_VERSION_X_Y_0 block

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily about this PR, but is the last 0 in TORCH_VERSION_X_Y_0 the ABI version? In the future that number may change, so we probably don't want to have our macro names be specialized to 0 prematurely.

replacement=None,
description=(
f"Call to versioned shim function '{func_name}' is not wrapped "
f"in a TORCH_FEATURE_VERSION block. This function requires at least:\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phrasing is a bit weird, but thats ok

#endif

// Function after #elif should not be versioned
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious: we're not expecting any nested ifdefs right?

@mikaylagawarecki mikaylagawarecki changed the title Add version linter for files that include torch/csrc/stable/c/shim.h Add version linter for files in torch/csrc/stable that use torch/csrc/stable/c/shim.h Jan 2, 2026
… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
#endif

#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
using StableIValue = uint64_t;

@mikaylagawarecki mikaylagawarecki Jan 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using StableIValue = uint64_t; is already in the aoti shim which is included in this file

(it also should not have minimum version 2.10)

hence removing

… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 3, 2026
… torch/csrc/stable/c/shim.h"

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```
 
2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0
 
 Doesn't error because this is still valid!
 
 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
 
 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(
        
```

4. Nested ifdefs 

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!
 
 




[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Jan 5, 2026
@mikaylagawarecki

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jan 5, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: docker-builds / docker-build (linux.12xlarge, pytorch-linux-noble-rocm-nightly-py3)

Details for Dev Infra team Raised by workflow job

@mikaylagawarecki

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: docker-builds / docker-build (linux.12xlarge, pytorch-linux-noble-rocm-nightly-py3)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: docker-builds / docker-build (linux.12xlarge, pytorch-linux-jammy-cuda13.0-cudnn9-py3-gcc11-inductor-benchmarks)

Details for Dev Infra team Raised by workflow job

@mikaylagawarecki

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: docker-builds / docker-build (linux.12xlarge, pytorch-linux-jammy-cuda13.0-cudnn9-py3-gcc11-inductor-benchmarks), docker-builds / docker-build (linux.12xlarge, pytorch-linux-noble-rocm-nightly-py3)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: linux-aarch64 / linux-jammy-aarch64-py3.10 / test (openreg, 1, 1, linux.arm64.m8g.4xlarge)

Details for Dev Infra team Raised by workflow job

@mikaylagawarecki

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: docker-builds / docker-build (linux.12xlarge, pytorch-linux-jammy-cuda13.0-cudnn9-py3-gcc11-inductor-benchmarks), docker-builds / docker-build (linux.12xlarge, pytorch-linux-noble-rocm-nightly-py3), linux-aarch64 / linux-jammy-aarch64-py3.10 / test (openreg, 1, 1, linux.arm64.m8g.4xlarge)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

krastogi-in pushed a commit to krastogi-in/pytorch that referenced this pull request Jan 9, 2026
…/stable/c/shim.h (pytorch#166996)

This PR ensures that files in `torch/csrc/stable` that include from `torch/csrc/stable/shim.h` properly gate calls to the stable shim APIs with the appropriate `TORCH_FEATURE_VERSION` macros

### Examples

1. Commenting out the version guard in

https://github.com/pytorch/pytorch/blob/a64c7d740428010d700b4bcd395af8a7b2d5c21f/torch/csrc/stable/ops.h#L265-L271

```
Error (STABLE_SHIM_USAGE) unversioned-shim-call
    Call to versioned shim function 'torch_call_dispatcher' is not wrapped in
    a TORCH_FEATURE_VERSION block. This function requires:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |  // #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |  // #else
        269  |  //   TORCH_ERROR_CODE_CHECK(
 ```

2. Changing the first line to say  #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0

 Doesn't error because this is still valid!

 3. Change that line to #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0

 ```
 Error (STABLE_SHIM_USAGE) insufficient-version-for-shim-call
    Call to 'torch_call_dispatcher' is wrapped in TORCH_VERSION_2_9_0, but
    this function requires at least TORCH_VERSION_2_10_0. The version guard
    must be at least the required version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
      // ... your code calling torch_call_dispatcher ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        263  |      torch::stable::detail::from(self),
        264  |      torch::stable::detail::from(std::nullopt)};
        265  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
    >>> 266  |  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
        267  |      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
        268  |#else
        269  |  TORCH_ERROR_CODE_CHECK(

```

4. Nested ifdefs

```
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

// We expect this to be the stable version of the clone op. We will
// add optional memory_format kwarg support in the future.
inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
  const auto num_args = 2;
  std::array<StableIValue, num_args> stack{
      torch::stable::detail::from(self),
      torch::stable::detail::from(std::nullopt)};
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
#endif
#ifdef FOO
  TORCH_ERROR_CODE_CHECK(torch_call_dispatcher(
      "aten::clone", "", stack.data(), TORCH_ABI_VERSION));
#else
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_call_dispatcher("aten::clone", "", stack.data()));
#endif
  return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
}

#endif
```

No error!

Pull Request resolved: pytorch#166996
Approved by: https://github.com/janeyx99
ghstack dependencies: pytorch#166995
@github-actions
github-actions Bot deleted the gh/mikaylagawarecki/363/head branch February 6, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants