Skip to content

YOLO-NAS model diverges with Vulkan backend #15700

Closed

Description

@lsauerr

🐛 Describe the bug

Hello,

I am trying to run a YOLO-NAS model on a GPU using a Vulkan backend.

I can lower and export the model to run it with the executor_runner, however, the first tensor on the outputs which represent the boxes coordinates diverge.
This behavior is not consistent. If I execute the same command line different outputs may be produced, even if I use the same input file. The command I am using is the following one:

./executor_runner --model_path=YOLO_NAS_S_vulkan.pte --inputs=dummy_input.bin

I did a minimal reproduction using the export.py available in executorch/examples/vulkan. I will attach the diff for you to reproduce it. To run it:

 python export.py --model=YOLO_NAS_S

I believe that @SS-JIA is the most suitable person to provide support for this.

export_diff.txt

Many thanks for your support.

Versions

Collecting environment information...
PyTorch version: 2.9.0+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 22.0.0git
CMake version: version 3.31.6
Libc version: glibc-2.35

Python version: 3.10.12 (main, May 27 2025, 17:12:29) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.8.0-60-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.5.119
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA RTX 2000 Ada Generation
Nvidia driver version: 570.133.07
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i9-14900
CPU family: 6
Model: 183
Thread(s) per core: 2
Core(s) per socket: 24
Socket(s): 1
Stepping: 1
CPU max MHz: 5800.0000
CPU min MHz: 800.0000
BogoMIPS: 3993.60
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 896 KiB (24 instances)
L1i cache: 1.3 MiB (24 instances)
L2 cache: 32 MiB (12 instances)
L3 cache: 36 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-31
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Mitigation; Clear Register File
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] executorch==1.0.0
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] onnx==1.15.0
[pip3] onnxruntime==1.15.0
[pip3] onnxsim==0.4.36
[pip3] pytorch-lightning==2.5.5
[pip3] pytorch_tokenizers==1.0.1
[pip3] torch==2.9.0
[pip3] torch-complex==0.4.4
[pip3] torchao==0.14.0+git01849b2b1
[pip3] torchaudio==2.9.0
[pip3] torchmetrics==0.8.0
[pip3] torchvision==0.24.0
[pip3] triton==3.5.0
[conda] Could not collect

cc @SS-JIA @manuelcandales @digantdesai @cbilgin

Activity

  1. added
    module: vulkan
    on Nov 10, 2025
  2. SS-JIA commented on Nov 10, 2025

    @SS-JIA
    Contributor

    @lsauerr thanks for reporting!

    Could you provide one or both:

    1. the .pte file you are testing with
    2. an export script that I can use to produce the .pte file you are testing with

    This will help me reproduce the issue and investigate further. Thanks in advance!

  3. lsauerr commented on Nov 10, 2025

    @lsauerr
    Author

    Thanks for the quick reply.
    I only extended what you did for the Vulkan examples. I put the diff of mine and yours in here.
    I can't send the *.pte file, I am receiving a message that this file type is not supported.

    To run it:

     python export.py --model=YOLO_NAS_S
    

    Many thanks for the support!

  4. SS-JIA commented on Nov 10, 2025

    @SS-JIA
    Contributor

    @lsauerr perfect, thanks. I will try to reproduce and will update when I have more news 👍

  5. SS-JIA commented on Nov 12, 2025

    @SS-JIA
    Contributor

    @lsauerr I was able to reproduce an issue where the model was producing incorrect output, and found that it was an issue with the split_with_sizes operator. I have created a fix here: #15793

    If you are able, it would be great if you could try pulling the fix and checking to see if the issue persists. Thanks in advance!

    P.S. For an easier repro, you can also use this PR #15795 where I add YOLO_NAS_S as an option in export.py

    git checkout gh/SS-JIA/371/head

    Pulling that branch will include the fix as well. Once the branch is checked out, you can test via

    # Install
    ./install_executorch.sh -e
    
    # Run export script and test
    MODEL_NAME=YOLO_NAS_S && \
    python -m examples.vulkan.export --model_name=$MODEL_NAME -o . --test
  6. lsauerr commented on Nov 13, 2025

    @lsauerr
    Author

    Many thanks for that!

    For anyone following this issue in the future, use the following to install (as pointed here):
    CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON " ./install_executorch.sh -e

    I did the process on your branch and the test passed. However, when executing it with the executor_runner, the values are still diverging (and thus presenting non-replicable results).

    I used the following to build the executor_runner, inside the branch you told me to checkout:

    cmake . \
         -DCMAKE_INSTALL_PREFIX=cmake-out \ 
         -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
         -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
         -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
         -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
         -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
         -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
         -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
         -DEXECUTORCH_BUILD_TESTS=ON \
         -DEXECUTORCH_BUILD_VULKAN=ON \
         -DGLSLC_PATH=$(which glslc) \
         -DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON \
         -Bcmake-out
    cmake --build cmake-out -j16 --target executor_runner
    

    To execute it:

    cmake-out/executor_runner --model_path=YOLO_NAS_S_vulkan.pte
    

    For what it is worth:
    - The behavior has been noticed for x86_64 architecture and for an aarch64.
    - I transformed the model using XnnpackPartitioner() instead of VulkanPartitioner() and executed it with executor_runner and the results did not diverge and were replicable across different runs.
    - I attached the produced output to show the divergence. You can notice it on the end of the first tensor, with values around e+30.

    output.txt

    I transformed the model using XnnpackPartitioner() instead of VulkanPartitioner() and executed it with executor_runner and the results did not diverge and were replicable across different runs.

    Any ideas on the cause? Many thanks for investigating it.

  7. SS-JIA commented on Nov 13, 2025

    @SS-JIA
    Contributor

    @lsauerr Unfortunately I'm not able to observe the divergence that you are seeing on my development machine. I actually tried on the main branch as well, and could not see the divergence (although the outputs did appear to be incorrect) so I think the divergence you are observing is coming from a separate issue entirely which is not being addressed by my fix.

    Here are some things you can try. First, if you are exporting with the -fp16 option, try to turn that off. Next, try exporting without memory planning. You can do this by running:

    MODEL_NAME=YOLO_NAS_S && \
    python -m examples.vulkan.export --model_name=$MODEL_NAME -o . --skip_memory_planning 

    Finally, I have posted my full repro instructions below - it may be helpful to try it out and compare with my uploaded results. If you have an Android device on hand, it may be helpful to test on that device as well to see if the issue may be something particular to the GPU you are testing on.

    For the record, I am testing on a machine equipped with an NVIDIA A100, here is the output of nvidia-smi:

    +-----------------------------------------------------------------------------------------+
    | NVIDIA-SMI 550.90.07              Driver Version: 550.90.07      CUDA Version: 12.4     |
    |-----------------------------------------+------------------------+----------------------+
    | GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
    |                                         |                        |               MIG M. |
    |=========================================+========================+======================|
    |   0  NVIDIA PG509-210               On  |   00000000:04:00.0 Off |                    0 |
    | N/A   29C    P0             48W /  330W |       6MiB /  81920MiB |      0%      Default |
    |                                         |                        |             Disabled |
    +-----------------------------------------+------------------------+----------------------+
                                                                                             
    +-----------------------------------------------------------------------------------------+
    | Processes:                                                                              |
    |  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
    |        ID   ID                                                               Usage      |
    |=========================================================================================|
    |  No running processes found                                                             |
    +-----------------------------------------------------------------------------------------+
    

    Here are my full repro instructions (outputs attached in a separate comment) for your reference. Note that I have updated my branch to make testing a bit easier, in particular adding the ability to save input data to export.py.

    # Checkout branch
    git checkout gh/SS-JIA/371/head
    
    # Install w/ Vulkan bindings
    CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" ./install_executorch.sh -e
    
    # Export and save inputs
    MODEL_NAME=YOLO_NAS_S && \                          
    python -m examples.vulkan.export --model_name=$MODEL_NAME -o . --test --save_inputs
    
    # Build for host
    cmake . \
        -DCMAKE_INSTALL_PREFIX=cmake-out \
        -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
        -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
        -DEXECUTORCH_BUILD_VULKAN=ON \
        -DEXECUTORCH_BUILD_TESTS=OFF \
        -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
        -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
        -DEXECUTORCH_BUILD_KERNELS_LLM=ON \
        -DEXECUTORCH_BUILD_KERNELS_LLM_AOT=ON \
        -DEXECUTORCH_BUILD_DEVTOOLS=ON \
        -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
        -Bcmake-out && \
    cmake --build cmake-out -j64 --target install
    
    # Run executor runner on host
    cmake-out/executor_runner --model_path=YOLO_NAS_S_vulkan.pte --inputs=input0.bin
    
    # Build for Android
    cmake . \
        -DCMAKE_INSTALL_PREFIX=cmake-out-android-so \
        -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
        -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \
        --preset "android-arm64-v8a" \
        -DANDROID_PLATFORM=android-28 \
        -DPYTHON_EXECUTABLE=python \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_C_COMPILER_LAUNCHER=ccache \
        -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
        -DEXECUTORCH_PAL_DEFAULT=posix \
        -DEXECUTORCH_BUILD_VULKAN=ON \
        -DEXECUTORCH_BUILD_TESTS=OFF \
        -DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON \
        -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
        -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
        -Bcmake-out-android-so && \
    cmake --build cmake-out-android-so -j16 --target install --config Release
    
    # Push artifacts
    adb shell mkdir -p /data/local/tmp/etvk/models/yolonas && \
    adb push YOLO_NAS_S_vulkan.pte /data/local/tmp/etvk/models/yolonas && \
    adb push input0.bin /data/local/tmp/etvk/models/yolonas && \
    adb push cmake-out-android-so/executor_runner /data/local/tmp/etvk
    
    # Run on Android
    PREFIX_PATH=/data/local/tmp/etvk/models/yolonas && \
    adb shell /data/local/tmp/etvk/executor_runner \
      --model_path=$PREFIX_PATH/YOLO_NAS_S_vulkan.pte --inputs=$PREFIX_PATH/input0.bin
  8. SS-JIA commented on Nov 13, 2025

    @SS-JIA
    Contributor

    Attached are the outputs I'm observing.

    Output when testing on the main branch on my development machine:
    yolonas_main.txt

    Output when testing on the gh/SS-JIA/371/head branch on my development machine:
    yolonas_with_fix.txt

    Output when testing on the gh/SS-JIA/371/head branch, on an Android device:
    yolonas_android_with_fix.txt

  9. SS-JIA commented on Nov 13, 2025

    @SS-JIA
    Contributor

    Re-uploading with stderr output as well so there's more context in the logs:

    yolonas_with_fix.txt

    yolonas_android_with_fix.txt

  10. 14 remaining items

  11. SS-JIA commented on Feb 4, 2026

    @SS-JIA
    Contributor

    @lsauerr

    To help us debug further, I've created a debugging script (#17224) to extract parts of the YOLONAS model to identify at which point the model outputs start to become incorrect.

    Would you be able to try running the script and letting me know the results? Thanks in advance 🙏

  12. lsauerr commented on Feb 5, 2026

    @lsauerr
    Author

    Hi @SS-JIA,

    Thanks for following up on this. I ran your script and the behavior was inconsistent: most of the time it passes, but eventually it fails for the full model. I haven't observed any occurrence of failure which happened before the full model pass.

    The logs are attached, the yolonas_debug-*-clean.log has only the logs that you inserted on the debug script, while the others contains the full console output (other files logs + warnings and dependencies messages from other packages).

    yolonas_debug-FAIL.log
    yolonas_debug-FAIL-clean.log
    yolonas_debug-PASS.log
    yolonas_debug-PASS-clean.log

    This runs were on the RTX 2000 ADA Generation GPU. Let me know if I can help you any further and again, many thanks for your great support!

  13. SS-JIA commented on Feb 5, 2026

    @SS-JIA
    Contributor

    @lsauerr thank you for that data! So basically, we're seeing that backbone + neck is always ok, but the full model fails occasionally for you. That should narrow it down to the heads part of the model.

    Will provide an update in a bit!

  14. SS-JIA commented on Feb 5, 2026

    @SS-JIA
    Contributor

    @lsauerr I updated the script in #17224 to isolate parts of the heads model.

    Based on the results, it's likely that the issue is somewhere in one of the following operators

      ┌──────────────────────────────────────────┐                                                                                                                      
      │                 Operator                 │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.view_copy.default                   │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.sigmoid.default                     │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.expand_copy.default                 │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.squeeze_copy.dims                   │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.unsqueeze_copy.default              │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.clone.default                       │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ dim_order_ops._to_dim_order_copy.default │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten._softmax.default                    │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.sub.Tensor                          │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.split_with_sizes_copy.default       │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.arange.start_step                   │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.full.default                        │                                                                                                                      
      ├──────────────────────────────────────────┤                                                                                                                      
      │ aten.permute_copy.default                │                                                                                                                      
      └──────────────────────────────────────────┘

    which is the list of operators that are included in the full model, but not the backbone/neck

  15. lsauerr commented on Feb 6, 2026

    @lsauerr
    Author

    Thanks for that @SS-JIA.

    I ran the updated script and the model passes the Heads but it still fails on Full Model execution, please find the log attached.

    yolonas_debug-HEADS-FAIL.log

    Maybe it is not an operator issue but a race condition during execution?

  16. SS-JIA commented on Feb 9, 2026

    @SS-JIA
    Contributor

    @lsauerr I was investigating another issue with inconsistent model outputs on an NVIDIA GPU, and discovered a bug in how the delegate is setting up memory barriers that could be causing the behaviour we are seeing here. A fix for the bug is in #17309 - could you try building with that fix and seeing if you are still observing the issue?

    On a separate note, did you ever try to export while disabling memory planning? This can be done via the compile options i.e.

    compile_options["skip_memory_planning"] = True

    If not, it would also be insightful to try this and see if you are still observing the same issue.

  17. lsauerr commented on Feb 10, 2026

    @lsauerr
    Author

    @SS-JIA I've just tried to build the executor_runner binary with the fix and I still see the issue. I Imagine that's what you meant, let me know if I understood incorrectly.

    I also tried to export it disabling the memory planning as you mentioned, and the issue persisted. As a reminder, I am seeing this behavior both for the NVIDIA GPU being used on the host on for the Arm Mali GPU being used on the target.

    If useful at all, here is the console output I see:

    stdout_stderr.txt

  18. SS-JIA commented on Feb 10, 2026

    @SS-JIA
    Contributor

    @lsauerr

    As a reminder, I am seeing this behavior both for the NVIDIA GPU being used on the host on for the Arm Mali GPU being used on the target.

    I do recall you mentioning the embedded GPU. What is the exactly model of the Arm Mali GPU, and are you testing it via an Android phone - if so, which one? I have Pixel 7 and Pixel 8 devices on hand that I can try to test with, and see if I can reproduce the divergence.

    Also, what's the rough frequency with which you see the behaviour? IIRC, you are not encountering the issue every inference but I may be wrong.

    Next steps:

    • I will try to reproduce on Pixel 7/8
    • I will provide some instructions on how to build and run operator level unit tests - it will be insightful if you can execute those and let me know if you are seeing any failures
  19. lsauerr commented on Feb 10, 2026

    @lsauerr
    Author

    @SS-JIA unfortunately I can't disclose the exact model of the GPU, sorry for that. Being Valhall architecture, I think it makes more sense to follow on with the Pixel 7 which has a Mali-G710 GPU.

    I am not testing on an android phone, but in a SoC which is running on Linux 5.10.205 generated through Yocto.

    Also, what's the rough frequency with which you see the behaviour? IIRC, you are not encountering the issue every inference but I may be wrong.

    That depends:

    • On the SoC with executor_runner in 10 runs, 2 diverged. This convergence rate has improved after rebuilding with the #17309.
    • On the host with executor_runner in 10 runs, 7 diverged
    • When I was using you debug script in #17224, the divergence (on the host) was very rare. I don't have precise numbers, but I would guess the tests failed 1 every 20 executions.

    The executor_runner tests were performed using a *.pte file generated with the skip_memory_planning option. Yet, for reasons that go beyond my comprehension, if I run the test within gdb, the divergence seems to occur every time.

  20. SS-JIA commented on Feb 14, 2026

    @SS-JIA
    Contributor

    @lsauerr sorry for the slow progress on this. Given that you are seeing this issue across both NVIDIA and Arm GPU, I don't think it's a driver specific issue. Perhaps the Vulkan backend has some kind of undefined behaviour in one of its shaders which is causing this divergent behaviour to manifest in certain drivers.

    I tested the model once again on NVIDIA A100, Pixel 8 Pro and Pixel 7 Pro - this time, setting up a script to execute the model N times and check that the outputs are consistent across all runs. However, I am still seeing that the model produces consistent outputs even with 50 runs.

    Repro Steps

    Export Model

    # Install w/ Vulkan bindings
    CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" ./install_executorch.sh -e
    
    # Export model + save input to current dir
    MODEL_NAME=YOLO_NAS_S && \                          
    python -m examples.vulkan.export --model_name=$MODEL_NAME -o . --save_inputs
    

    Run on Development Machine Setup

    cmake . \
        -DCMAKE_INSTALL_PREFIX=cmake-out \
        -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
        -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
        -DEXECUTORCH_BUILD_VULKAN=ON \
        -DEXECUTORCH_BUILD_TESTS=OFF \
        -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
        -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
        -DEXECUTORCH_BUILD_KERNELS_LLM=ON \
        -DEXECUTORCH_BUILD_KERNELS_LLM_AOT=ON \
        -DEXECUTORCH_BUILD_DEVTOOLS=ON \
        -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
        -Bcmake-out && \
    cmake --build cmake-out -j64 --target install
    
    # Test run
    cmake-out/executor_runner \
     --model_path=./YOLO_NAS_S_vulkan.pte \
     --inputs=./input0.bin

    Runner script

    #!/bin/bash
    # Reproduction script for https://github.com/pytorch/executorch/issues/15700
    # Runs YOLO_NAS_S_vulkan.pte 10 times and checks for output divergence.
    
    set -euo pipefail
    
    RUNNER="cmake-out/executor_runner"
    MODEL="./YOLO_NAS_S_vulkan.pte"
    INPUTS="./input0.bin"
    NUM_RUNS=50
    
    TMPDIR=$(mktemp -d)
    trap 'rm -rf "$TMPDIR"' EXIT
    
    echo "Running $RUNNER $NUM_RUNS times..."
    echo "Model: $MODEL"
    echo "Inputs: $INPUTS"
    echo ""
    
    for i in $(seq 1 $NUM_RUNS); do
        outfile="$TMPDIR/run_$i.txt"
        # Capture only stdout lines starting with "Output" or tensor data (indented
        # lines / lines with brackets), skipping log lines (I ...:) and the etdump
        # line.
        "$RUNNER" \
            --model_path="$MODEL" \
            --inputs="$INPUTS" \
            2>&1 \
            | grep -v '^I ' \
            > "$outfile"
        echo "Run $i done"
    done
    
    echo ""
    
    # Compare all runs against run 1
    baseline="$TMPDIR/run_1.txt"
    all_match=true
    for i in $(seq 2 $NUM_RUNS); do
        outfile="$TMPDIR/run_$i.txt"
        if ! diff -q "$baseline" "$outfile" > /dev/null 2>&1; then
            all_match=false
            echo "DIVERGENCE: run 1 vs run $i"
            diff "$baseline" "$outfile" | head -40
            echo "---"
        fi
    done
    
    if $all_match; then
        echo "All $NUM_RUNS runs produced identical output."
    else
        echo ""
        echo "Output divergence detected across $NUM_RUNS runs."
    fi

    Run on Android Setup

    # Build runner binary for android
    cmake . \
        -DCMAKE_INSTALL_PREFIX=cmake-out-android-so \
        -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
        -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \
        --preset "android-arm64-v8a" \
        -DANDROID_PLATFORM=android-28 \
        -DPYTHON_EXECUTABLE=python \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_C_COMPILER_LAUNCHER=ccache \
        -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
        -DEXECUTORCH_PAL_DEFAULT=posix \
        -DEXECUTORCH_BUILD_VULKAN=ON \
        -DEXECUTORCH_BUILD_TESTS=OFF \
        -DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON \
        -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
        -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
        -Bcmake-out-android-so && \
    cmake --build cmake-out-android-so -j16 --target install --config Release
    
    # Push Artifacts
    adb shell mkdir -p /data/local/tmp/etvk/models/yolonas && \
    adb push YOLO_NAS_S_vulkan.pte /data/local/tmp/etvk/models/yolonas && \
    adb push input0.bin /data/local/tmp/etvk/models/yolonas && \
    adb push cmake-out-android-so/executor_runner /data/local/tmp/etvk

    Script to execute multiple times and check all outputs are the same

    #!/bin/sh
    
    # yolonas_divergence_test.sh
    
    set -euo pipefail
    
    NUM_RUNS="${1:-10}"
    DEVICE_PREFIX="/data/local/tmp/etvk"
    MODEL_DIR="$DEVICE_PREFIX/models/yolonas_s"
    MODEL_PATH="$MODEL_DIR/YOLO_NAS_S_vulkan.pte"
    INPUT_PATH="$MODEL_DIR/input0.bin"
    RUNNER="$DEVICE_PREFIX/executor_runner"
    
    WORKDIR=$(mktemp -d)
    trap 'rm -rf "$WORKDIR"' EXIT
    
    echo "=== YOLO-NAS Vulkan Divergence Test ==="
    echo "Runs: $NUM_RUNS"
    echo "Working dir: $WORKDIR"
    echo ""
    
    # Verify device is connected
    if ! adb get-state >/dev/null 2>&1; then
        echo "ERROR: No Android device connected"
        exit 1
    fi
    
    # Verify files exist on device
    if ! adb shell "test -f $MODEL_PATH" 2>/dev/null; then
        echo "ERROR: Model not found at $MODEL_PATH on device"
        echo "Run the setup commands from yolonas_ondevice.sh first"
        exit 1
    fi
    
    divergence_count=0
    reference_file=""
    
    for i in $(seq 1 "$NUM_RUNS"); do
        output_file="$WORKDIR/run_$i.txt"
    
        echo "--- Run $i/$NUM_RUNS ---"
    
        # Run the model, capture output. The executor_runner aborts at the end
        # trying to write ETDump, so we ignore the exit code.
        adb shell "$RUNNER --model_path=$MODEL_PATH --inputs=$INPUT_PATH" \
            >"$output_file" 2>&1 || true
    
        # Check that the model actually executed
        if ! grep -q "Model executed successfully" "$output_file"; then
            echo "  WARNING: Model execution may have failed"
            cat "$output_file"
            continue
        fi
    
        # Extract OutputX 0 (bounding box tensor) for comparison.
        # Grab from "OutputX 0:" up to the next "OutputX " or end.
        sed -n '/^OutputX 0:/,/^OutputX [1-9]/{ /^OutputX [1-9]/!p; }' \
            "$output_file" > "$WORKDIR/output0_run_$i.txt"
    
        if [ -z "$reference_file" ]; then
            reference_file="$WORKDIR/output0_run_$i.txt"
            echo "  Reference run captured"
        else
            compare_file="$WORKDIR/output0_run_$i.txt"
            if diff -q "$reference_file" "$compare_file" >/dev/null 2>&1; then
                echo "  MATCH - output matches reference"
            else
                divergence_count=$((divergence_count + 1))
                echo "  DIVERGED - output differs from reference!"
                # Show a brief diff of the first few differing lines
                diff "$reference_file" "$compare_file" | head -20
            fi
        fi
    done
    
    echo ""
    echo "=== Results ==="
    echo "Total runs: $NUM_RUNS"
    echo "Divergent runs: $divergence_count / $((NUM_RUNS - 1)) (first run is reference)"
    
    if [ "$divergence_count" -gt 0 ]; then
        echo "CONCLUSION: Non-determinism DETECTED"
        exit 1
    else
        echo "CONCLUSION: All outputs matched (no divergence detected)"
        exit 0
    fi

    Output:

    === YOLO-NAS Vulkan Divergence Test ===
    Runs: 10
    Working dir: /var/folders/ch/wpn5l1rx3p17k4r6w3mhsdgr0000gn/T/tmp.FWPyOJ454Q
    
    --- Run 1/10 ---
      Reference run captured
    --- Run 2/10 ---
      MATCH - output matches reference
    --- Run 3/10 ---
      MATCH - output matches reference
    --- Run 4/10 ---
      MATCH - output matches reference
    --- Run 5/10 ---
      MATCH - output matches reference
    --- Run 6/10 ---
      MATCH - output matches reference
    --- Run 7/10 ---
      MATCH - output matches reference
    --- Run 8/10 ---
      MATCH - output matches reference
    --- Run 9/10 ---
      MATCH - output matches reference
    --- Run 10/10 ---
      MATCH - output matches reference
    
    === Results ===
    Total runs: 10
    Divergent runs: 0 / 9 (first run is reference)
    CONCLUSION: All outputs matched (no divergence detected)
    
  21. SS-JIA commented on Feb 14, 2026

    @SS-JIA
    Contributor

    @lsauerr

    I would greatly appreciate it if you could help me grab some debug info from your machine 🙏

    I've set up #17466 to add debug logging to the compute shaders to try and detect at what point tensor values start to become extremely large. You should be able to enable debug prints on your development machine via the Vulkan SDK (the Vulkan Configuration app specifically).

    You can get the changes by pulling the gh/SS-JIA/431/head branch. Afterwards, you should be able to see some output like the following when outputs diverge:

    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(2, 1568, 0, 0), value=408.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(3, 1568, 0, 0), value=176.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(0, 1569, 0, 0), value=376.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(1, 1569, 0, 0), value=136.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(2, 1569, 0, 0), value=416.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(3, 1569, 0, 0), value=176.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(0, 1570, 0, 0), value=384.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(1, 1570, 0, 0), value=136.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(2, 1570, 0, 0), value=424.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(3, 1570, 0, 0), value=176.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(0, 1571, 0, 0), value=392.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(1, 1571, 0, 0), value=136.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(2, 1571, 0, 0), value=432.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(3, 1571, 0, 0), value=176.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(0, 1572, 0, 0), value=400.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(1, 1572, 0, 0), value=136.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(2, 1572, 0, 0), value=440.000000
    [print_buffer] value_ref=483, sizes=(4, 8400, 1, 1), idx=(3, 1572, 0, 0), value=176.000000

    Note that the threshold in the print shaders should be 1e5, but I set it to 1e2 temporarily to demonstrate the prints.

    Also, there may be a lot of output, please save everything to a file so everything is captured!

  22. SS-JIA commented on Feb 15, 2026

    @SS-JIA
    Contributor

    Tested on NVIDIA RTX 4080 as well, no divergence over 50 runs.

  23. lsauerr commented on Feb 16, 2026

    @lsauerr
    Author

    Hi @SS-JIA, many thanks for all your effort on this!

    I ran the tests on my development machine following the repro steps you mentioned. I hope these logs can help you:
    runner_script.log
    vk_debug.log

    You should be able to enable debug prints on your development machine via the Vulkan SDK (the Vulkan Configuration app specifically).

    I set the validation layers as specified by Khronos group here. I also set the buffer size to something greater than the default:

    export VK_LAYER_PRINTF_ONLY_PRESET=1
    export VK_LAYER_PRINTF_BUFFER_SIZE=32768

    Good luck hacking!

  24. lsauerr commented on Jun 2, 2026

    @lsauerr
    Author

    Closing this issue. I have not seen this behavior on more recent releases of ExecuTorch, so probably this got fixed.

    As a note, I was able to obtain the correct outputs for YOLO-NAS model by using the DFL output tensor, which contains the boxes coordinates and labels.

    Thanks for the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module: vulkan

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions