Pytorch backend#5
Open
mt-caret wants to merge 4 commits into
Open
Conversation
Add a torch backend that interprets fox tensor programs on Torch.Tensor.t, mirroring the eager Tensor backend op-for-op via Op.Make_operators, primarily for differential testing. - lib/torch (fox_torch): Pytorch.Backend implements Operators_intf.S over Torch.Tensor.t; Pytorch.handle interprets each Fox_effect.Op through libtorch analogous to Handler.eval. fox float64 <-> torch Double and fox Bool <-> torch Uint8 (comparisons yield Bool), converted via bigarrays. - lib/core: expose Fox_effect and Operators_intf from the fox_core wrapper (needed to author an external backend + handler); add Tensor.Private.to_char_bigarray symmetric to the existing float/of_char converters. - test: quickcheck eager-vs-torch over single-op programs (relative tolerance, since torch transcendentals differ from libm by ~ULPs whereas the eager allclose is absolute), plus a deterministic Bool round-trip test. Builds CPU-only against a manually supplied libtorch 2.7.1 and a CPU patch to the torch package; see lib/torch/README.md and PLAN.md for the rationale. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Guarantee matmul/transpose/sum (Just/negative dims, keep_dims) and a sum+broadcast+div composition (mean) are exercised against the eager backend, rather than relying on quickcheck's random op draws. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
torch was pinned to an ephemeral local directory, so the CPU patch wasn't reproducible. Capture it instead as: - opam-overlay/: a local opam-repository whose only package, torch.v0.18~preview.130.91+190, is the ox repo's definition plus `patches: ["torch-cpu.patch"]`. It fetches the upstream tarball by checksum and applies files/torch-cpu.patch (the CUDA-removal + link-propagation diff), so no patched sources are vendored. - fox.opam.locked regenerated to pin every dependency to exact versions, now including torch and the ctypes 0.23.x it pulls in. Reproduce with the overlay out-ranking ox + `opam install . --locked` (see lib/torch/README.md). Verified by re-deriving the patched torch from upstream + the committed patch, installing it from the overlay, and running the full test suite green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI hard-depends on torch now, but the runner had neither libtorch nor the opam-overlay, so torch failed to compile (missing headers) / would have used the unpatched upstream sources. Mirror the local setup: download CPU libtorch 2.7.1 and export LIBTORCH, register opam-overlay/ at rank 1 so its patched torch wins for the shared version, and key the switch cache on the overlay too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.