Phantom ML compiler: declarative model definitions compiled to native code via LLVM. pip install phantom-lang; import phantom.
Project description
phantom — Python bindings for Phantom
Idiomatic Python bindings for the Phantom
compiler. Calls JIT-compiled Phantom shapes against numpy arrays in one
function call — no ctypes, no manual buffer management, no dylib path
juggling.
Install
pip install maturin
git clone https://github.com/menezzo/phantom
cd phantom/crates/phantom-pyo3
maturin develop --release
A pip install phantom wheel is the next ship; until then, maturin develop builds the extension module in-place against your active
Python interpreter.
Quickstart
import numpy as np
import phantom
# Run a Phantom shape from a .ph file with a numpy float32 input.
out = phantom.run(
"examples/two_host_pipeline.ph",
np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float32),
)
print(out) # numpy array
# With pre-loaded weights from a directory of .npy files.
out = phantom.run(
"examples/gpt2.ph",
np.load("/tmp/phantom-gpt2-golden/input.npy"),
weights_dir="/tmp/phantom-gpt2-golden",
)
print(out.shape) # (32, 256)
# Or compile from a source string (for inline notebook use).
src = """
shape add_one =
it ~> add 1.0
"""
out = phantom.run_source(src, np.array([1.0, 2.0, 3.0], dtype=np.float32))
print(out) # [2., 3., 4.]
Contract
- f32 only: numpy arrays must be
dtype=np.float32. Other dtypes raiseTypeErrorat the boundary. Cast explicitly with.astype(np.float32)if you need to. - C-contiguous only: non-contiguous arrays raise
ValueError. Usenp.ascontiguousarray(arr)to convert. - Errors are Python exceptions: parse/resolve/typecheck/lower failures
raise
RuntimeErrorwith the rendered diagnostic; runtime errors do the same. No status codes, no thread-local error strings.
What this wraps
phantom.run and phantom.run_source are thin wrappers over
phantom_driver::run_pipeline::compile_and_invoke. The same JIT pipeline
that powers phantom-driver run from the CLI also powers these calls,
so the numerical results match bit-identical (or within floating-point
noise) between the Python API and the CLI.
The Phantom GPT-2 model that matches PyTorch within 1.79e-07 via the C FFI also matches PyTorch via this API — same JIT, same MLIR, same LLVM codegen, just a different ergonomic shell.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 56.1 MB
- Tags: CPython 3.9+, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07d64f04035edda6b63695eec35cd7c2b6a4cccdb543d9090e743a3fb6ed91f1
|
|
| MD5 |
68900e3f1c9230bfad90cc0b45d7b184
|
|
| BLAKE2b-256 |
f03f8ac2786cf419301496b720c38174e5e419ed5711cf0fae8bdf17e1f26f5f
|
Provenance
The following attestation bundles were made for phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl:
Publisher:
pypi-publish.yml on menezzo/phantom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl -
Subject digest:
07d64f04035edda6b63695eec35cd7c2b6a4cccdb543d9090e743a3fb6ed91f1 - Sigstore transparency entry: 1289156887
- Sigstore integration time:
-
Permalink:
menezzo/phantom@105bcf9890c5ae997a6ca46d64b1e8263eb8cc97 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/menezzo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@105bcf9890c5ae997a6ca46d64b1e8263eb8cc97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 39.6 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
498c11e84ea11eae95c9b07f8361ba8817dc1e817382495726e1dda433c4b4c2
|
|
| MD5 |
ca32abb7eed9d72a56f6b73639afe40c
|
|
| BLAKE2b-256 |
8d533212d242cfbcbcfef1c2db988bf8ac951b92954f6899b6854c34b6b8fc8a
|
Provenance
The following attestation bundles were made for phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
pypi-publish.yml on menezzo/phantom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
498c11e84ea11eae95c9b07f8361ba8817dc1e817382495726e1dda433c4b4c2 - Sigstore transparency entry: 1289156956
- Sigstore integration time:
-
Permalink:
menezzo/phantom@105bcf9890c5ae997a6ca46d64b1e8263eb8cc97 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/menezzo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@105bcf9890c5ae997a6ca46d64b1e8263eb8cc97 -
Trigger Event:
push
-
Statement type: