Skip to content

[MPS] compat: torch.accelerator module exists but is not exported at top level #275

Description

@lvyufeng

Summary

A recent upstream change added src/candle/accelerator.py, but the beginner tensor tutorial still fails because Candle does not expose accelerator on the top-level torch/candle module.

So the issue is no longer 'module missing on disk' — it is now specifically a top-level export / compat surface wiring gap.

Current state

Upstream now contains:

  • src/candle/accelerator.py

But src/candle/__init__.py still does not expose accelerator, so this still fails:

import torch
print(torch.accelerator.is_available())

when USE_CANDLE=1 redirects torch to Candle.

Environment

  • Repo: candle-org/candle
  • Tested from latest upstream/main on 2026-03-27
  • Commit tested: f37302f
  • macOS Apple Silicon
  • Python 3.11.15
  • Candle installed editable from a fresh worktree
  • Torch compat hook installed via python -m candle.torch_compat install
  • Repro run with USE_CANDLE=1

Minimal reproduction

source ~/miniconda3/etc/profile.d/conda.sh && conda run -n candle311-tutorials \
  env USE_CANDLE=1 python -c "import torch; print(torch.accelerator.is_available())"

Observed

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'candle' has no attribute 'accelerator'

Expected

If src/candle/accelerator.py is the intended compatibility implementation, it should be reachable through the top-level compat surface so that:

torch.accelerator.is_available()
torch.accelerator.current_accelerator()

work under USE_CANDLE=1.

Tutorial impact

This still blocks:

  • beginner/basics/tensorqs_tutorial.py

Likely source

  • src/candle/accelerator.py now exists
  • src/candle/__init__.py does not re-export or otherwise attach accelerator

Related

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