Repository navigation
Description
🐛 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/flatcSo I exported it
export FLATC_EXECUTABLE=$PWD/.venv/lib/python3.11/site-packages/executorch/data/bin/flatc
uv run ./my_script.pyENV
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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
manuelcandales commentedon Jan 30, 2026
cc @JacobSzwejbka
JacobSzwejbka commentedon Jan 30, 2026
@GregoryComer have you seen this before?
GregoryComer commentedon Apr 2, 2026
@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?
Red-Eyed commentedon Apr 3, 2026
I installed it via
uv:uv add executorchnil-is-all commentedon Jul 29, 2026
Hi @Red-Eyed, sorry for the delay. Do you still face this bug with the latest version?
ErenAta16 commentedon Sep 11, 2026
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.pydeliberately adds the platform suffix when packaging:and the binary duly arrives as
executorch/data/bin/flatc.exe. Butexir/_serialize/_flatbuffer.py:275asks for it without the suffix:Checked live against an installed 1.4.1 wheel:
Neither candidate matches, so the loop falls through to
os.getenv("FLATC_EXECUTABLE", "flatc")at line 302 and Python tries to spawn abare
flatcfrom PATH. With no system flatc installed that isFileNotFoundError: [WinError 2], raised out of_run_flatcat line 337. Thebinary 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.Linearmodule,to_edge_transform_and_lowerwithXnnpackPartitioner, thento_executorch:The middle row is the useful one for anyone blocked today: pointing
FLATC_EXECUTABLEat the bundledflatc.exeworks, which also isolates thedefect to the lookup rather than to flatc, the partitioner or the serializer.
The one-line shape that fixes it, mirroring what
setup.pyalready does:osis 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 ratherthan 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.
ErenAta16 commentedon Sep 11, 2026
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
findlocated the binary atsite-packages/executorch/data/bin/flatc, with the correct unsuffixed name. Thatlooks 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 thelookup never looked there. Before
0d904b6b("Add minimal wheel build mode",#19899, 6 June 2026) the function checked exactly one candidate:
that is,
executorch/exir/_serialize/flatbuffers-flatcand nothing else. #19899replaced it with the two-candidate loop that added
("executorch.data.bin", "flatc"). So in January the binary was packaged intodata/bin/while the resolver only knew about_serialize/, and it fell straightthrough to the bare
flatcon PATH. That is yourFileNotFoundError: [Errno 2],and your
FLATC_EXECUTABLEworkaround 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", whilesetup.pypackages throughget_executable_name(),which makes the file
flatc.exeon Windows. So the candidate that fixed Linuxstill 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
mainand am happyto send it whenever a maintainer says go.
cc @GregoryComer @JacobSzwejbka since you both asked for a reproduction path in
the thread.
nil-is-all commentedon Sep 15, 2026
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
ErenAta16 commentedon Oct 19, 2026
Thanks @nil-is-all. The Windows case is filed as #23989 and the fix is in #23992.
Re-measuring against 1.5.1 and
mainchanged 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.pyruns an XNNPACKto_executorch()export. Second, "dies on Windows" was too broad. The failure needs the environment'sScriptsdirectory to be offPATH(interpreter called by its full path, no activation); with it onPATH, the bareflatcfallback 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-flatcnext to_flatbuffer.py(I re-checkedv1.1.0:exir/_serialize/_flatbuffer.py), and #19899 added theexecutorch.data.bincandidate afterwards. So I think this issue can be closed for @Red-Eyed's case, as you suggested, once #23992 is in.nil-is-all commentedon Oct 21, 2026
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.