Skip to content

Add version linter for torch/csrc/stable/c/shim.h - #166995

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

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

Conversation

@mikaylagawarecki

@mikaylagawarecki mikaylagawarecki commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes. are properly within TORCH_FEATURE_VERSION blocks like

#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are

  • function declarations start with AOTI_TORCH_EXPORT (we will have to update if this changes in the future)
  • version macros look like TORCH_VERSION_{major}_{minor}_{patch} (where we ignore patch)

Examples

Adding torch_call_dispatcher_v2 outside preprocessor macros fails like

Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,

Add torch_call_dispatcher_v2 within TORCH_VERSION_2_9_0 block

Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
   New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
   in TORCH_VERSION_2_9_0. New additions in this commit must use the current
   version:
   #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
   // ... your declarations ...
   #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

       17  |
       18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
       19  |
   >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
       21  |    const char* opName,
       22  |    const char* overloadName,
       23  |    StableIValue* stack,

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/166995

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

❌ 1 New Failure, 1 Cancelled Job

As of commit 6b05d87 with merge base 3f09374 (image):

NEW FAILURE - The following job has failed:

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

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

This is a linter lints the most recent commit + any uncommited changes. It makes sure new functions added to torch/csrc/stable/shim.h are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
@mikaylagawarecki mikaylagawarecki mentioned this pull request Nov 4, 2025
This is a linter lints the most recent commit + any uncommited changes. It makes sure new functions added to torch/csrc/stable/shim.h are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter lints the most recent commit + any uncommited changes. It makes sure new functions added to torch/csrc/stable/shim.h are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
@mikaylagawarecki mikaylagawarecki changed the title Add version linter for torch/csrc/stable/shim.h Add version linter for torch/csrc/stable/c/shim.h Nov 5, 2025
This is a linter lints the most recent commit + any uncommited changes. It makes sure new functions added to torch/csrc/stable/shim.h are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: ea4d44e
Pull Request resolved: #166995
@mikaylagawarecki
mikaylagawarecki marked this pull request as ready for review November 6, 2025 18:22
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: af3a5e6
Pull Request resolved: #166995
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
mikaylagawarecki added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: 0b52d50
Pull Request resolved: #166995
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
if result.returncode == 0:
added_lines.update(parse_diff(result.stdout))

# Also check the most recent commit (HEAD vs HEAD~1)

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.

Does this mean if there's a stack of N commits, each one will have different linter complaints compared to the one before? I guess there's no easy merge branch cuz it'll be different on trunk...

Khanaksahu pushed a commit to Khanaksahu/pytorch-fork that referenced this pull request Nov 17, 2025
Khanaksahu pushed a commit to Khanaksahu/pytorch that referenced this pull request Nov 17, 2025
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are 
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```
 
 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block
 
 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```





[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #166996

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #166996

2 similar comments
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #166996

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #166996

pytorchmergebot pushed a commit that referenced this pull request Jan 6, 2026
…/stable/c/shim.h (#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: #166996
Approved by: https://github.com/janeyx99
ghstack dependencies: #166995
krastogi-in pushed a commit to krastogi-in/pytorch that referenced this pull request Jan 9, 2026
This is a linter makes sure functions add to the shim.h in the most recent commit + any uncommited changes.  are properly within TORCH_FEATURE_VERSION blocks like

```
#if TORCH_FEATURE_VERSION >= <current TORCH_ABI_VERSION>

...

#endif
```

and all other functions in the file are wrapped in TORCH_FEATURE_VERSION macros

The assumptions here are
- function declarations start with `AOTI_TORCH_EXPORT` (we will have to update if this changes in the future)
- version macros look like `TORCH_VERSION_{major}_{minor}_{patch}` (where we ignore patch)

### Examples

Adding `torch_call_dispatcher_v2` outside preprocessor macros fails like

```
Error (STABLE_SHIM_VERSION) unversioned-function-declaration
    Function declaration found outside of TORCH_FEATURE_VERSION block. All
    function declarations must be wrapped in:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        15  |extern "C" {
        16  |#endif
        17  |
    >>> 18  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        19  |    const char* opName,
        20  |    const char* overloadName,
        21  |    StableIValue* stack,
 ```

 Add `torch_call_dispatcher_v2` within TORCH_VERSION_2_9_0 block

 ```
 Error (STABLE_SHIM_VERSION) wrong-version-for-new-function
    New function declaration should use TORCH_VERSION_2_10_0, but is wrapped
    in TORCH_VERSION_2_9_0. New additions in this commit must use the current
    version:
    #if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
    // ... your declarations ...
    #endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0

        17  |
        18  |#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_9_0
        19  |
    >>> 20  |AOTI_TORCH_EXPORT AOTITorchError torch_call_dispatcher_v2(
        21  |    const char* opName,
        22  |    const char* overloadName,
        23  |    StableIValue* stack,
 ```

Pull Request resolved: pytorch#166995
Approved by: https://github.com/janeyx99
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
SergeyTyshkevich pushed a commit to SergeyTyshkevich/chart2 that referenced this pull request Jan 19, 2026
@github-actions
github-actions Bot deleted the gh/mikaylagawarecki/362/head branch February 6, 2026 02:22
pytorchmergebot pushed a commit that referenced this pull request Jul 27, 2026
…y fetch (#191228)

The STABLE_SHIM_VERSION linter intermittently fails in CI with
`subprocess.TimeoutExpired` on `git diff <merge_base>..HEAD -- shim.h`,
reported as an internal linter bug.

Root cause: CI checks out a blobless partial clone (`--filter=blob:none`, added
in #172544; see .github/actions/checkout-pytorch/action.yml). The 5s diff
timeout predates that (added with the linter in #166995) and was correct then --
the diff was purely local. `merge_base_with_main()` fetches the merge-base
*commit* ahead of time, but the blobless filter deliberately omits file contents
even for explicitly fetched commits, so the merge-base blob of the linted file
is never local. When `git diff` needs it, git triggers an on-demand lazy fetch
in the middle of the command -- an uncontrolled network round-trip that races
the 5s timeout under the network contention of lintrunner running adapters
concurrently.

This is the same partial-clone symptom #189419 already fixed for the sibling
`git cat-file` probe in `merge_base_with_main()`, which was simply never applied
to the `git diff`/`git show` paths. #189419 established the design: keep a short
timeout as a fast "is it local?" probe and, on absence, fall back to an
explicit, controlled `git fetch`. #189444 tried to instead bump the probe
timeout to wait the lazy fetch out; #189946 reverted that, on the grounds that a
timeout is the signal that the object is not present, not something to wait out.
So bumping the diff timeout (or wrapping the diff in the retrying fetch helper to
wait it out) would repeat the already-reverted mistake.

Fix: apply #189419's design to the missing blob. `ensure_diff_blob_local()`
resolves the blob OID offline (trees are present under blob:none) and, only if
it is missing locally, fetches that single object through the existing retrying
network helper; the diff/show then runs entirely from local objects with a
short, honest timeout. `GIT_NO_LAZY_FETCH=1` guards the resolution and presence
checks so they cannot themselves trigger a fetch -- a deterministic improvement
over the cat-file probe's timeout race. In a full clone the blob is already
present and this is a no-op with no network access. The generated-shims linter's
prior 60s `git show` workaround is replaced by the same prefetch + 5s timeout.

Test Plan:
Verified locally in a full clone that the helper is a no-op and the git command
stays local and fast:

```
python tools/linter/adapters/stable_shim_version_linter.py \
    torch/csrc/inductor/aoti_torch/c/shim.h
```

End-to-end validation on a blobless partial clone still needs to run (the
sandbox has no network); it must confirm the single-blob
`git fetch --no-write-fetch-head origin <oid>` succeeds against GitHub's
promisor endpoint. If the explicit single-object fetch is rejected there, the
fallback is to trigger git's native lazy fetch through the same retry wrapper
(e.g. `git cat-file -p <oid>`).

Authored-with: Claude (AI assistant)
Pull Request resolved: #191228
Approved by: https://github.com/albanD, https://github.com/Skylion007, https://github.com/janeyx99
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…y fetch (pytorch#191228)

The STABLE_SHIM_VERSION linter intermittently fails in CI with
`subprocess.TimeoutExpired` on `git diff <merge_base>..HEAD -- shim.h`,
reported as an internal linter bug.

Root cause: CI checks out a blobless partial clone (`--filter=blob:none`, added
in pytorch#172544; see .github/actions/checkout-pytorch/action.yml). The 5s diff
timeout predates that (added with the linter in pytorch#166995) and was correct then --
the diff was purely local. `merge_base_with_main()` fetches the merge-base
*commit* ahead of time, but the blobless filter deliberately omits file contents
even for explicitly fetched commits, so the merge-base blob of the linted file
is never local. When `git diff` needs it, git triggers an on-demand lazy fetch
in the middle of the command -- an uncontrolled network round-trip that races
the 5s timeout under the network contention of lintrunner running adapters
concurrently.

This is the same partial-clone symptom pytorch#189419 already fixed for the sibling
`git cat-file` probe in `merge_base_with_main()`, which was simply never applied
to the `git diff`/`git show` paths. pytorch#189419 established the design: keep a short
timeout as a fast "is it local?" probe and, on absence, fall back to an
explicit, controlled `git fetch`. pytorch#189444 tried to instead bump the probe
timeout to wait the lazy fetch out; pytorch#189946 reverted that, on the grounds that a
timeout is the signal that the object is not present, not something to wait out.
So bumping the diff timeout (or wrapping the diff in the retrying fetch helper to
wait it out) would repeat the already-reverted mistake.

Fix: apply pytorch#189419's design to the missing blob. `ensure_diff_blob_local()`
resolves the blob OID offline (trees are present under blob:none) and, only if
it is missing locally, fetches that single object through the existing retrying
network helper; the diff/show then runs entirely from local objects with a
short, honest timeout. `GIT_NO_LAZY_FETCH=1` guards the resolution and presence
checks so they cannot themselves trigger a fetch -- a deterministic improvement
over the cat-file probe's timeout race. In a full clone the blob is already
present and this is a no-op with no network access. The generated-shims linter's
prior 60s `git show` workaround is replaced by the same prefetch + 5s timeout.

Test Plan:
Verified locally in a full clone that the helper is a no-op and the git command
stays local and fast:

```
python tools/linter/adapters/stable_shim_version_linter.py \
    torch/csrc/inductor/aoti_torch/c/shim.h
```

End-to-end validation on a blobless partial clone still needs to run (the
sandbox has no network); it must confirm the single-blob
`git fetch --no-write-fetch-head origin <oid>` succeeds against GitHub's
promisor endpoint. If the explicit single-object fetch is rejected there, the
fallback is to trigger git's native lazy fetch through the same retry wrapper
(e.g. `git cat-file -p <oid>`).

Authored-with: Claude (AI assistant)
Pull Request resolved: pytorch#191228
Approved by: https://github.com/albanD, https://github.com/Skylion007, https://github.com/janeyx99
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…y fetch (pytorch#191228)

The STABLE_SHIM_VERSION linter intermittently fails in CI with
`subprocess.TimeoutExpired` on `git diff <merge_base>..HEAD -- shim.h`,
reported as an internal linter bug.

Root cause: CI checks out a blobless partial clone (`--filter=blob:none`, added
in pytorch#172544; see .github/actions/checkout-pytorch/action.yml). The 5s diff
timeout predates that (added with the linter in pytorch#166995) and was correct then --
the diff was purely local. `merge_base_with_main()` fetches the merge-base
*commit* ahead of time, but the blobless filter deliberately omits file contents
even for explicitly fetched commits, so the merge-base blob of the linted file
is never local. When `git diff` needs it, git triggers an on-demand lazy fetch
in the middle of the command -- an uncontrolled network round-trip that races
the 5s timeout under the network contention of lintrunner running adapters
concurrently.

This is the same partial-clone symptom pytorch#189419 already fixed for the sibling
`git cat-file` probe in `merge_base_with_main()`, which was simply never applied
to the `git diff`/`git show` paths. pytorch#189419 established the design: keep a short
timeout as a fast "is it local?" probe and, on absence, fall back to an
explicit, controlled `git fetch`. pytorch#189444 tried to instead bump the probe
timeout to wait the lazy fetch out; pytorch#189946 reverted that, on the grounds that a
timeout is the signal that the object is not present, not something to wait out.
So bumping the diff timeout (or wrapping the diff in the retrying fetch helper to
wait it out) would repeat the already-reverted mistake.

Fix: apply pytorch#189419's design to the missing blob. `ensure_diff_blob_local()`
resolves the blob OID offline (trees are present under blob:none) and, only if
it is missing locally, fetches that single object through the existing retrying
network helper; the diff/show then runs entirely from local objects with a
short, honest timeout. `GIT_NO_LAZY_FETCH=1` guards the resolution and presence
checks so they cannot themselves trigger a fetch -- a deterministic improvement
over the cat-file probe's timeout race. In a full clone the blob is already
present and this is a no-op with no network access. The generated-shims linter's
prior 60s `git show` workaround is replaced by the same prefetch + 5s timeout.

Test Plan:
Verified locally in a full clone that the helper is a no-op and the git command
stays local and fast:

```
python tools/linter/adapters/stable_shim_version_linter.py \
    torch/csrc/inductor/aoti_torch/c/shim.h
```

End-to-end validation on a blobless partial clone still needs to run (the
sandbox has no network); it must confirm the single-blob
`git fetch --no-write-fetch-head origin <oid>` succeeds against GitHub's
promisor endpoint. If the explicit single-object fetch is rejected there, the
fallback is to trigger git's native lazy fetch through the same retry wrapper
(e.g. `git cat-file -p <oid>`).

Authored-with: Claude (AI assistant)
Pull Request resolved: pytorch#191228
Approved by: https://github.com/albanD, https://github.com/Skylion007, https://github.com/janeyx99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants