Skip to content

flatc is not found but is present #17000

Closed
Closed

Description

@Red-Eyed

🐛 Describe the bug

flatc is not found when trying to export

Export code:

@torch.no_grad()
def to_executorch(model, dst_file: Path):
    inputs = model.example_input
    model = model.eval()
    exported_program = torch.export.export(model, tuple(inputs.values()), strict=True)
    executorch_program = to_edge_transform_and_lower(
        exported_program,
        partitioner=[XnnpackPartitioner()],
    ).to_executorch()

    dst_file.write_bytes(executorch_program.buffer)

Traceback

Traceback (most recent call last):
  File ".venv/lib/python3.11/site-packages/executorch/exir/program/_program.py", line 115, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/exir/program/_program.py", line 1379, in to_edge_transform_and_lower
    edge_manager = edge_manager.to_backend(method_to_partitioner)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/exir/program/_program.py", line 115, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/exir/program/_program.py", line 1681, in to_backend
    new_edge_programs = to_backend(method_to_programs_and_partitioners)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/redeyed/.local/share/uv/python/cpython-3.11.11-linux-x86_64-gnu/lib/python3.11/functools.py", line 909, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/exir/backend/backend_api.py", line 762, in _
    lower_all_submodules_to_backend(
  File ".venv/lib/python3.11/site-packages/executorch/exir/backend/backend_api.py", line 591, in lower_all_submodules_to_backend
    backend_name_to_subclass[backend_id].preprocess_multimethod(
  File ".venv/lib/python3.11/site-packages/executorch/exir/backend/backend_details.py", line 145, in preprocess_multimethod
    preprocess_result = cls.preprocess(program, compile_spec_for_program)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/backends/xnnpack/xnnpack_preprocess.py", line 189, in preprocess
    processed_bytes=serialize_xnnpack_binary(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/backends/xnnpack/serialization/xnnpack_graph_serialize.py", line 347, in serialize_xnnpack_binary
    flatbuffer_payload = convert_to_flatbuffer(xnnpack_graph)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/executorch/backends/xnnpack/serialization/xnnpack_graph_serialize.py", line 328, in convert_to_flatbuffer
    _flatc_compile(d, schema_path, json_path)
  File ".venv/lib/python3.11/site-packages/executorch/exir/_serialize/_flatbuffer.py", line 216, in _flatc_compile
    _run_flatc(
  File ".venv/lib/python3.11/site-packages/executorch/exir/_serialize/_flatbuffer.py", line 202, in _run_flatc
    subprocess.run([flatc_path] + list(args), check=True)
  File "/home/redeyed/.local/share/uv/python/cpython-3.11.11-linux-x86_64-gnu/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/redeyed/.local/share/uv/python/cpython-3.11.11-linux-x86_64-gnu/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/redeyed/.local/share/uv/python/cpython-3.11.11-linux-x86_64-gnu/lib/python3.11/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'flatc'

Workaround

I tried to find flatc and found it

find .venv/lib/python3.11/site-packages/executorch/ -name flatc
.venv/lib/python3.11/site-packages/executorch/data/bin/flatc

So I exported it

export FLATC_EXECUTABLE=$PWD/.venv/lib/python3.11/site-packages/executorch/data/bin/flatc
uv run ./my_script.py

ENV

executorch 1.1.0
pytorch-lightning 2.6.0
pytorch-tokenizers 1.1.0
torch 2.10.0+cu128
torchao 0.15.0
torchdata 0.11.0
torchmetrics 1.8.2
torchvision 0.25.0+cu128
vector-quantize-pytorch 1.27.20

OS: Ubuntu 24.04

Versions

uv run collect_env.py
Collecting environment information...
PyTorch version: 2.10.0+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.3 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 4.2.1
Libc version: glibc-2.39

Python version: 3.11.11 (main, Mar 17 2025, 21:02:09) [Clang 20.1.0 ] (64-bit runtime)
Python platform: Linux-6.8.0-90-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to:
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 5070 Ti
GPU 1: NVIDIA GeForce RTX 2060 SUPER

Nvidia driver version: 580.126.09
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i9-9900KF CPU @ 3.60GHz
CPU family: 6
Model: 158
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 13
CPU(s) scaling MHz: 42%
CPU max MHz: 5000,0000
CPU min MHz: 800,0000
BogoMIPS: 7200,00
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 pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp vnmi md_clear flush_l1d arch_capabilities ibpb_exit_to_user
Virtualization: VT-x
L1d cache: 256 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 2 MiB (8 instances)
L3 cache: 16 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; Enhanced IBRS
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 SW loop, KVM SW loop
Vulnerability Srbds: Mitigation; Microcode
Vulnerability Tsx async abort: Mitigation; TSX disabled
Vulnerability Vmscape: Mitigation; IBPB before exit to userspace

Versions of relevant libraries:
[pip3] Could not collect
[conda] Could not collect

cc @JacobSzwejbka @angelayi @GregoryComer @digantdesai @cbilgin

Activity

  1. added
    module: exir
    on Jan 29, 2026
  2. manuelcandales commented on Jan 30, 2026

    @manuelcandales
    Contributor
  3. JacobSzwejbka commented on Jan 30, 2026

    @JacobSzwejbka
    Contributor

    @GregoryComer have you seen this before?

  4. added
    triaged
    on Jan 30, 2026
  5. added
    module: xnnpack
    on Feb 2, 2026
  6. GregoryComer commented on Apr 2, 2026

    @GregoryComer
    Contributor

    @JacobSzwejbka I haven't, unfortunately. @Red-Eyed Can you share exactly how you set up the venv? Did you install executorch via pip or from source?

  7. Red-Eyed commented on Apr 3, 2026

    @Red-Eyed
    Author

    I installed it via uv: uv add executorch

  8. nil-is-all commented on Jul 29, 2026

    @nil-is-all
    Contributor

    Hi @Red-Eyed, sorry for the delay. Do you still face this bug with the latest version?

  9. ErenAta16 commented on Sep 11, 2026

    @ErenAta16
    Contributor

    Root cause for the Windows form of this, since the thread has been asking for one
    since January and nobody has named it. On Windows the wheel ships the binary and
    the lookup can never find it, because the two disagree about the filename.

    setup.py deliberately adds the platform suffix when packaging:

    def get_executable_name(name: str) -> str:
        if _is_windows():
            return name + ".exe"
        else:
            return name

    and the binary duly arrives as executorch/data/bin/flatc.exe. But
    exir/_serialize/_flatbuffer.py:275 asks for it without the suffix:

    for package, resource_name in (
        (__package__, _FLATC_RESOURCE_NAME),
        ("executorch.data.bin", "flatc"),
    ):

    Checked live against an installed 1.4.1 wheel:

    executorch.exir._serialize   flatc      is_file=False
    executorch.data.bin          flatc      is_file=False     <- what the code asks for
    executorch.data.bin          flatc.exe  is_file=True      <- what the wheel ships
    

    Neither candidate matches, so the loop falls through to
    os.getenv("FLATC_EXECUTABLE", "flatc") at line 302 and Python tries to spawn a
    bare flatc from PATH. With no system flatc installed that is
    FileNotFoundError: [WinError 2], raised out of _run_flatc at line 337. The
    binary is sitting in site-packages the whole time, which is exactly the "present
    but not found" in the title.

    RED/GREEN, executorch 1.4.1, torch 2.14.0+cpu, Python 3.12.10, Windows 11
    x86_64. Minimal nn.Linear module, to_edge_transform_and_lower with
    XnnpackPartitioner, then to_executorch:

    unmodified                                    FileNotFoundError: [WinError 2]
    FLATC_EXECUTABLE=<site-packages>/data/bin/flatc.exe   lowers cleanly
    resource name given a ".exe" suffix on nt             lowers cleanly
    

    The middle row is the useful one for anyone blocked today: pointing
    FLATC_EXECUTABLE at the bundled flatc.exe works, which also isolates the
    defect to the lookup rather than to flatc, the partitioner or the serializer.

    The one-line shape that fixes it, mirroring what setup.py already does:

    _exe_suffix = ".exe" if os.name == "nt" else ""
    for package, resource_name in (
        (__package__, _FLATC_RESOURCE_NAME + _exe_suffix),
        ("executorch.data.bin", "flatc" + _exe_suffix),
    ):

    os is already imported in that module, so nothing else changes.

    On why this survived: the wheel is exercised by .ci/scripts/test_minimal_wheel.sh,
    a shell script, so the path that would catch it does not run on Windows. That is
    the usual reason a packaging bug reaches a release with green CI.

    One caveat on scope. @Red-Eyed's traceback shows
    .venv/lib/python3.11/site-packages/..., which reads as Linux or macOS rather
    than Windows, and on those platforms the unsuffixed name is correct. So I have
    explained the Windows instance of this symptom and I am not claiming it is the
    same one you hit. If you were on Windows, or under WSL calling a Windows
    interpreter, this is it; if you were on Linux, the shipped binary is missing or
    unreadable for a different reason and that is worth separating out.

    Happy to send the fix as a PR if a maintainer wants it. I have it working locally
    and can add a test that asserts the resolved path exists rather than one that
    shells out.

  10. ErenAta16 commented on Sep 11, 2026

    @ErenAta16
    Contributor

    Following up on my own caveat, because the Linux half has an answer too and it is
    a different one.

    @Red-Eyed you were on 1.1.0 and your find located the binary at
    site-packages/executorch/data/bin/flatc, with the correct unsuffixed name. That
    looks like it should have matched, so I went back through the history of
    exir/_serialize/_flatbuffer.py. It did not match because at that point the
    lookup never looked there. Before 0d904b6b ("Add minimal wheel build mode",
    #19899, 6 June 2026) the function checked exactly one candidate:

    flatc_resource = importlib.resources.files(__package__).joinpath(_FLATC_RESOURCE_NAME)
    if flatc_resource.is_file():
        ...
    else:
        ...FLATC_EXECUTABLE...

    that is, executorch/exir/_serialize/flatbuffers-flatc and nothing else. #19899
    replaced it with the two-candidate loop that added
    ("executorch.data.bin", "flatc"). So in January the binary was packaged into
    data/bin/ while the resolver only knew about _serialize/, and it fell straight
    through to the bare flatc on PATH. That is your FileNotFoundError: [Errno 2],
    and your FLATC_EXECUTABLE workaround is exactly the fallback the code reached.

    Which answers @nil-is-all's July question for the original report: on Linux this
    was fixed on 6 June and 1.1.0 predates it.

    What is still live is only the Windows form, and it is the same commit's doing
    from the other direction. #19899 got the directory right and the filename wrong:
    it hardcoded "flatc", while setup.py packages through get_executable_name(),
    which makes the file flatc.exe on Windows. So the candidate that fixed Linux
    still cannot match there, which is what I measured on 1.4.1 in my previous comment.

    That makes the whole thread one bug with two dates rather than two bugs: the
    resolver did not know the directory until June, and it still does not know the
    platform suffix.

    So this is closeable for @Red-Eyed's case and open for Windows. Given that, the
    one-line change I offered is a completion of #19899 rather than a new fix, which
    may make it easier to take. I have it working locally against main and am happy
    to send it whenever a maintainer says go.

    cc @GregoryComer @JacobSzwejbka since you both asked for a reproduction path in
    the thread.

  11. nil-is-all commented on Sep 15, 2026

    @nil-is-all
    Contributor

    Hi @ErenAta16, could you file a separate issue and a PR which fixes the Windows issue which is persistent? I can review and merge the fix, and we can close this issue for the Linux side. Appreciate your contribution!
    cc @JakeStevens @JacobSzwejbka

  12. ErenAta16 commented on Oct 19, 2026

    @ErenAta16
    Contributor

    Thanks @nil-is-all. The Windows case is filed as #23989 and the fix is in #23992.

    Re-measuring against 1.5.1 and main changed two things I said earlier in this thread, so I want to correct them here.

    First, I wrote that the path that would catch this does not run on Windows. That was wrong: .ci/scripts/wheel/test_windows.py runs an XNNPACK to_executorch() export. Second, "dies on Windows" was too broad. The failure needs the environment's Scripts directory to be off PATH (interpreter called by its full path, no activation); with it on PATH, the bare flatc fallback finds pip's console-script shim and the export works. Both are written up with the numbers in #23989.

    The Linux/macOS half is unchanged from my earlier comment: 1.1.0 only looked for flatbuffers-flatc next to _flatbuffer.py (I re-checked v1.1.0:exir/_serialize/_flatbuffer.py), and #19899 added the executorch.data.bin candidate afterwards. So I think this issue can be closed for @Red-Eyed's case, as you suggested, once #23992 is in.

  13. nil-is-all commented on Oct 21, 2026

    @nil-is-all
    Contributor

    Closing this as resolved and #23989 now tracks the Windows part of the flatc issue. Thanks @ErenAta16
    @Red-Eyed feel free to re-open if necessary.

  14. moved this from To triage to Done in ExecuTorch Coreon Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: exirmodule: xnnpacktriaged

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions