Skip to main content

High-performance machine learning library with lazy evaluation and automatic kernel fusion

Project description

zyx - Python Bindings

PyPI version License: LGPL 3.0

zyx is a high-performance machine learning library for Python, powered by Rust. It features lazy evaluation, automatic kernel fusion, and multi-backend support (CPU, GPU via OpenCL/CUDA/WebGPU).

Note: Install with pip install zyx-py, then import as import zyx

Installation

pip install zyx-py

Requirements:

  • Python 3.5+
  • Linux x86_64 (more platforms coming soon)

Quick Start

import zyx

# Create tensors
x = zyx.Tensor([1.0, -2.0, 3.0])
y = zyx.Tensor([4.0, 5.0, 6.0])

# Lazy evaluation - operations build a graph
z = x.relu() + y

# Realize to compute the result
z.realize()
print(z.numpy())  # [5.0, 5.0, 9.0]

# Random tensors
a = zyx.Tensor.randn(3, 3)
b = zyx.Tensor.randn(3, 3)
c = a @ b  # Matrix multiplication
c.realize()

Key Features

  • Lazy Evaluation - Operations accumulate until realize(), reducing temporary allocations
  • Kernel Fusion - Multiple operations compile into single optimized GPU kernels
  • Immutable Tensors - No in-place modification errors common in other frameworks
  • Explicit Gradient Tape - Control what's recorded, no no_grad() semantics needed
  • Arbitrary-Order Gradients - Native support for 2nd, 3rd, and higher-order derivatives
  • Cross-Platform - OpenCL (CPU/GPU), WebGPU, CUDA/ROCm backends

Tensor Operations

Creation

import zyx

# From Python lists
t1 = zyx.Tensor([1, 2, 3])

# Random initialization
t2 = zyx.Tensor.randn(100, 100)
t3 = zyx.Tensor.rand((50, 50), dtype=zyx.DType.F32)

# Constant tensors
zeros = zyx.Tensor.zeros(10, 10)
ones = zyx.Tensor.ones(10, 10)
eye = zyx.Tensor.eye(5)

# Full tensor with specific value
filled = zyx.Tensor.full((3, 3), 2.5)

# With numpy arrays
import numpy as np
arr = np.array([[1, 2], [3, 4]])
t = zyx.Tensor(arr)

Math Operations

x = zyx.Tensor.randn(100, 100)

# Unary operations
y = x.relu()
y = x.sigmoid()
y = x.tanh()
y = x.gelu()
y = x.softmax(dim=-1)
y = x.log_softmax(dim=-1)

# Binary operations
a = zyx.Tensor.randn(100, 100)
b = zyx.Tensor.randn(100, 100)
c = a + b
c = a - b
c = a * b
c = a / b
c = a.matmul(b)  # Matrix multiplication

# Reduction operations
mean = x.mean(dim=0)
sum_val = x.sum(dim=1)
max_val = x.max(dim=-1)
min_val = x.min(dim=-1)
argmax = x.argmax(dim=-1)
argmin = x.argmin(dim=-1)

# Shape operations
y = x.reshape(10, 10)
y = x.transpose(0, 1)
y = x.permute(1, 0, 2)
y = x.squeeze()
y = x.unsqueeze(0)

# Realize to get numpy array
result = y.numpy()

Automatic Differentiation

import zyx

# Create a gradient tape
tape = zyx.GradientTape()

# Forward pass
x = zyx.Tensor([1.0, 2.0, 3.0])
w = zyx.Tensor([0.5, 0.5, 0.5])
y = (x * w).sum()

# Compute gradients
grads = tape.gradient(y, [w])
print(grads[0].numpy())  # [1.0, 2.0, 3.0]

# Higher-order gradients
tape2 = zyx.GradientTape()
y = x.relu().sum()
grads = tape2.gradient(y, [x])

Neural Network Modules

import zyx
import zyx.nn as nn

# Linear layer
linear = nn.Linear(in_features=128, out_features=64)

# Convolutional layer
conv = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=(3, 3))

# Normalization layers
ln = nn.LayerNorm(normalized_shape=(128,))
bn = nn.BatchNorm(num_features=64)
gn = nn.GroupNorm(num_groups=8, num_channels=64)
rn = nn.RMSNorm(dim=128)

# Activation functions
x = zyx.Tensor.randn(10, 128)
y = x.relu()
y = x.gelu()
y = x.silu()

# Multihead attention
attn = nn.MultiheadAttention(embed_dim=512, num_heads=8)
query = zyx.Tensor.randn(32, 128, 512)  # batch, seq, embed
key = zyx.Tensor.randn(32, 128, 512)
value = zyx.Tensor.randn(32, 128, 512)
output, _ = attn(query, key, value)

# Transformer layers
encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8)
transformer = nn.TransformerEncoder(encoder_layer, num_layers=6)

Optimizers

import zyx
import zyx.nn as nn
import zyx.optim as optim

# Create model
model = nn.Linear(10, 5)

# Create optimizer
optimizer = optim.Adam(learning_rate=0.001)
# or: optim.SGD(learning_rate=0.01, momentum=0.9)
# or: optim.AdamW(learning_rate=0.001, weight_decay=0.01)
# or: optim.RMSprop(learning_rate=0.001)

# Training loop
tape = zyx.GradientTape()
x = zyx.Tensor.randn(32, 10)
target = zyx.Tensor.randn(32, 5)

# Forward
pred = model(x)
loss = ((pred - target) ** 2).mean()

# Backward
grads = tape.gradient(loss, model.get_params())
optimizer.update(model, grads)

# Realize all pending computations
zyx.Tensor.realize_all()

Training Example

import zyx
import zyx.nn as nn
import zyx.optim as optim

# Set random seed
zyx.manual_seed(42)

# Create model
class SimpleNet:
    def __init__(self):
        self.fc1 = nn.Linear(784, 128)
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x):
        x = self.fc1(x).relu()
        x = self.fc2(x)
        return x

    def get_params(self):
        return self.fc1.get_params() + self.fc2.get_params()

    def set_params(self, params):
        self.fc1.set_params(params[:2])
        self.fc2.set_params(params[2:])

model = SimpleNet()
optimizer = optim.Adam(learning_rate=0.001)

# Training loop
for epoch in range(10):
    tape = zyx.GradientTape()

    # Dummy data
    x = zyx.Tensor.randn(64, 784)
    y = zyx.Tensor.randint(0, 10, (64,))

    # Forward pass
    logits = model.forward(x)
    loss = logits.cross_entropy(y)

    # Backward pass
    grads = tape.gradient(loss, model.get_params())
    optimizer.update(model, grads)

    # Compute accuracy
    pred = logits.argmax(dim=-1)
    acc = (pred == y).float().mean()

    zyx.Tensor.realize_all()
    print(f"Epoch {epoch}, Loss: {loss.numpy():.4f}, Acc: {acc.numpy():.4f}")

Data Types

import zyx

# Supported dtypes
zyx.DType.F32    # 32-bit float
zyx.DType.F64    # 64-bit float
zyx.DType.F16    # 16-bit float
zyx.DType.BF16   # BFloat16
zyx.DType.I8     # 8-bit int
zyx.DType.I16    # 16-bit int
zyx.DType.I32    # 32-bit int
zyx.DType.I64    # 64-bit int
zyx.DType.U8     # 8-bit uint
zyx.DType.U16    # 16-bit uint
zyx.DType.U32    # 32-bit uint
zyx.DType.U64    # 64-bit uint
zyx.DType.Bool   # Boolean

# Create tensor with specific dtype
t = zyx.Tensor([1, 2, 3], dtype=zyx.DType.F32)

Device Support

zyx automatically selects the best available backend:

  • OpenCL - CPU and GPU support via POCL or vendor drivers
  • WebGPU - Modern cross-platform GPU API
  • CUDA/ROCm - NVIDIA and AMD GPU support

To check or set the runtime backend, use environment variables:

export ZYX_BACKEND=opencl    # Use OpenCL backend
export ZYX_BACKEND=wgpu      # Use WebGPU backend
export ZYX_BACKEND=cuda      # Use CUDA backend

Debug Options

Enable debug output with the ZYX_DEBUG environment variable:

ZYX_DEBUG=1    # Print hardware devices
ZYX_DEBUG=2    # Print performance info
ZYX_DEBUG=4    # Print kernel scheduling
ZYX_DEBUG=8    # Print kernel IR
ZYX_DEBUG=16   # Print native assembly

Combine flags: ZYX_DEBUG=18 (2 + 16) for perf + assembly output.

Why zyx?

Feature zyx PyTorch
Gradient recording Explicit GradientTape Implicit, requires no_grad()
Tensor mutability Immutable (no in-place errors) Mutable (can cause back-prop failures)
Higher-order gradients Arbitrary order natively Supported but more complex
Kernel fusion Automatic via lazy graph Manual or via torch.compile
Disk I/O Lazy loading parallel to compute Typically blocking

License

LGPL-3.0-only - see LICENSE file for details.

Links

Status

Experimental - API is stabilizing, performance under active optimization. Not production-ready yet.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zyx_py-0.15.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp314-cp314-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

zyx_py-0.15.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp313-cp313-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

zyx_py-0.15.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp312-cp312-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

zyx_py-0.15.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp311-cp311-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

zyx_py-0.15.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp310-cp310-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

zyx_py-0.15.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp39-cp39-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

zyx_py-0.15.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

zyx_py-0.15.4-cp38-cp38-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file zyx_py-0.15.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cbaaabc31198bc34b794a8afef89cc4f3f835b3c1b4e62a7be7af39abe3f07ee
MD5 d1687580baa9e3c0aca63e772363a24e
BLAKE2b-256 ea7dbb696c68f87a587d569a615ccbeae16d634a6f8fae432c7907164f25bda2

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f19c13266d7a6025d97affe95673546c2d2eaacbb6f3ecdb86211fa817b8a93a
MD5 1547c77b55eb1afa47b91b96e3a67034
BLAKE2b-256 b93c1119d4be949c3ad972bcda4c6e372a9419243e99bcfbc738a0af5d797bf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 735aa05eb2521e2113c015716d05f5ce0bf3abe582afa51487505887a507a0a1
MD5 98c6d0172a109a0e0b2e328b5fcacac4
BLAKE2b-256 2489623f92b6797e4c60cd235fa457cadcc1a0568b367692629e7197ed146afb

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0dfaaa0fe663ebe313d64058fe0a640d98becb7b1383ec2324e49efaf8ae4c9
MD5 fa35a747a10d2caaf01254c108b398b9
BLAKE2b-256 58b0888d69cd0c43b649075e598ae2dc13e2af6cbcbced3c23a2b8330b74a51e

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1af521f2cc42d447381d32dc32acd19b1655368fa39d63eb19c8392094db52bc
MD5 7a4886272706b248c639ae79bc146d7d
BLAKE2b-256 b802a1f562c64c9bb04a35ef345f536721936394b96d38570c75c514f8bd6683

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44a4b270b553361b097de55c96db8b8102f8abc6443a4ad79ba9b90707fcb836
MD5 14aaa02a3a7c049efabf17d49e0b9c5b
BLAKE2b-256 0bc600f0f68cfc4c24409c267252137c35766e3559c7cabcdcc7525eb8b9fab8

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02f3e9baa1b86c2531ae30a6a37b3976448a41226bad9ede1fdd2b50b985c737
MD5 afe78023b1d9777e739f401a3d3b0bf5
BLAKE2b-256 83bc9b4b429675aa4f30932a956a54b561a2d1d8d5c31f1553d63628ae910773

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4afec30a0235f3cf28468b690b57cf49fbcba5ef89fe042aaa10e8a4bb815fde
MD5 b691e989857365b73279777cfead21a8
BLAKE2b-256 c439581edf10ef632e425fa34ae6ac4904cb921535072feadca55c2288e638bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b520fc38e9389816ea4f3a3a2a0324a74d9916c2c0bd0bfbb456d468be069744
MD5 510119546cda6e5379bf1a83c35ed52b
BLAKE2b-256 df9e3fd1703bbe71c6123732a6f76193448a6ff40ffc3f31b4cdcb23d38303c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d574fc50198a6ff66e7f58e81ad569dd43101de2d18b0882a6681da2b31f4fa
MD5 d1833bd77df9efba7a2905a7326b6524
BLAKE2b-256 3a00c2a3a8623c60f8739ab7c90b5987692703ef501f88eec56448376efa68f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af016c205d7b8c5a030992164f76bf814f06690c389e31d92fcc625e006a73dc
MD5 029da0140c1918653719b7bcf4fc2890
BLAKE2b-256 bd6273f6088188c638859accca89a8fc5abba6607535c5572e2616773c5a5cfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c11280ecf9ffb48791c47ed4ac157320cbc398e868a24437156a8c75f124a62
MD5 f3078d1b701a1eea2626cee3b5200d1a
BLAKE2b-256 b265a195dcd1c03a13ce35c9b6ef9e685151c83fa91b07889dd83ae098b27185

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 144ea7a57720ef4fa126f974b0df728ab57b63595141f17c786437b3cc83db46
MD5 768783183b359838bbac1ee339e172a1
BLAKE2b-256 8b3096ca721b54023aa0affb3675b8a61d3b247401f0064fc63d2907d6658cda

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zyx_py-0.15.4-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zyx_py-0.15.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d7cd774c1486dd1577e037da47e1df2cd363ec7f06d2e48b6fe973ec476d263
MD5 81c81838dc0c45ddf8c8979995e8e6be
BLAKE2b-256 5595b93fccb584ad0ed50b0c254044044ec38079b9a943ea9042e23258b94b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for zyx_py-0.15.4-cp38-cp38-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on zk4x/zyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page