Skip to main content

A C++ deep learning library with Vulkan GPU acceleration, exposed to Python

Project description

wefml

C++ deep learning library with optional CUDA/Vulkan GPU acceleration, packaged for Python.

Install

pip install wefml

Requires Python >= 3.8, CMake >= 3.15, C++17 compiler. CUDA or Vulkan are auto-detected at build time; CPU-only mode works out of the box.

Quick Start

import wefml
import numpy as np

a = wefml.Tensor.from_numpy(np.random.randn(2, 3).astype(np.float32))
b = wefml.Tensor.from_numpy(np.random.randn(3, 4).astype(np.float32))
c = wefml.ops.matmul(a, b)
print(c.numpy())

Sequential Model

model = wefml.Model([
    wefml.Linear(128, use_bias=True),
    wefml.ReLU(),
    wefml.Linear(10, use_bias=True),
])
model.fit(labels, inputs, epochs=10, lr=0.01)
pred = model.predict(test_inputs)

Transformer (English-to-Spanish)

A built-in encoder-decoder transformer for seq2seq tasks. The bundled english_spanish_tab.txt is resolved automatically.

import wefml

tok = wefml.Tokenizer()
tok.process("english_spanish_tab.txt", early_stop=4000)
data = wefml.prepare_translation_data(tok, val_size=50)

model = wefml.Transformer(
    vocab_size=data["vocab_size"],
    d_model=64,
    num_heads=4,
    batch_size=50,
)

model.train(
    data["enc"], data["dec"], data["target"],
    data["val_enc"], data["val_dec"], data["val_target"],
    epochs=10, lr=0.05,
)
print(model.loss)

test_input = data["val_enc"]  # single [1, maxlen] sample
output = model.generate(test_input, data["start_token"], data["end_token"], max_tokens=10)
print(output.numpy())

GPU Mode

print(wefml.gpu_backend())   # 'cuda', 'vulkan', or 'none'
wefml.use_gpu(True)          # Linear/Conv2D/MaxPool2D auto-pick GPU variants

model = wefml.Model([...], use_gpu=True)
# or
model = wefml.Transformer(vocab_size=vocab, use_gpu=True)

API Reference

GPU -- use_gpu(bool), is_gpu_available(), is_cuda_available(), is_vulkan_available(), gpu_backend()

Tensor -- Tensor.from_numpy(arr), Tensor.zeros(shape), .numpy(), .shape, .rank, .size, arithmetic (+, -, *, /)

Ops (wefml.ops) -- matmul, matmul_mt, transpose, argmax, softmax, relu, sigmoid, reducesum, positional_encoding, l2, binarycrossentropy

Layers -- Linear, Conv2D, MaxPool2D, ReLU, Sigmoid, Flatten, LayerNorm, ReduceSum, Embedding, MHA

Model -- Model(layers, use_gpu) with .add(), .fit(), .predict(), .summary()

Transformer -- Transformer(vocab_size, d_model=128, num_heads=4, batch_size=50, use_gpu=False) with .train(), .generate(), .loss

Data -- Tokenizer().process(path, early_stop), prepare_translation_data(tok, val_size), load_mnist_images(path), load_mnist_labels(path)

License

MIT

Project details


Download files

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

Source Distribution

wefml-0.1.5.tar.gz (2.9 MB view details)

Uploaded Source

File details

Details for the file wefml-0.1.5.tar.gz.

File metadata

  • Download URL: wefml-0.1.5.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for wefml-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a4565cc7e549a6f32d167d8299653650682a7f23707d792958c07e65c8ad1718
MD5 446b2cae83e1315e7f09b281d2e645e9
BLAKE2b-256 6d74b3efcbd1d40b5ce4922d2ae0abf2519160ea3acdd2401ae04daad7aa268b

See more details on using hashes here.

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