Skip to content

[Frontend] Single-CPU runs crash: extension_codecache.py calls future.result() on the str AsyncCompile.submit returns inline #542

Open

Description

@YWHyuk

Summary

With only one usable CPU, every simulated kernel launch on the master frontend crashes with
AttributeError: 'str' object has no attribute 'result'.

MLIRAsyncCompile.mlir() in PyTorchSimFrontend/extension_codecache.py assumes self.submit(task) returns a
Future, then calls future.result() (line 284 on master @ 509f425, and the same line in release v1.1.0).
Inductor's AsyncCompile.submit() does not return a Future when compile_threads <= 1. In that case it runs the
task inline and returns its result, which here is the key str:

# torch/_inductor/async_compile.py (torch 2.8.0), line 283
@classmethod
def submit(cls, task: Callable[..., Any]) -> Any:
    if get_compile_threads() <= 1:
        return task()
    return cls.pool().submit(task)

Inductor sets compile_threads from the number of usable CPUs, so this happens on any 1-CPU container, Slurm job
or cgroup (for example docker run --cpuset-cpus 0, or srun -c 1).

Reproduce

Image ghcr.io/psal-postech/torchsim-ci:v1.1.0 (PyTorchSim f595cef, torch 2.8.0+cu126):

docker run --rm --entrypoint= --cpuset-cpus 5 ghcr.io/psal-postech/torchsim-ci:v1.1.0 \
  bash -lc 'cd /workspace && python3 PyTorchSim/tests/test_matmul.py'
compile_threads 1
...
  File "/workspace/PyTorchSim/PyTorchSimFrontend/extension_codecache.py", line 284, in run_kernel_simulation
    key = future.result()
          ^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'result'

The same command with TORCHINDUCTOR_COMPILE_THREADS=2 (or with two or more CPUs) passes.

Suggested fix

Handle both return types:

future = self.submit(task)
...
key = future.result() if hasattr(future, "result") else future

Alternatively, always submit to a pool.

Notes

  • The pytorchsim-triton-backend branch has a different frontend and no extension_codecache.py. This report
    covers master and v1.1.0 only.
  • Workaround until a fix lands: set TORCHINDUCTOR_COMPILE_THREADS=2.
  • Found while running PyTorchSim as a single-core benchmark (one pinned CPU per run).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions