!
Archived versionYou are viewing documentation for v0.3.0. View latest (v0.4.0) docs

vectorphile

v0.3.0 Archived

Production completeness — 41 modules, 50+ DL architectures, 5-tier GPU dispatch, full tokenizer suite, pretrained hub, RL algorithms, GGUF export, Lightning-style Trainer, and advanced optimizers. Replaces PyTorch + HuggingFace Transformers + scikit-learn under a single original API.

Overview

vectorphile v0.3.0 reaches production completeness with 41 modules covering every corner of the ML ecosystem. The 5-tier backend dispatch makes it match PyTorch GPU speed when Triton, Numba or CuPy are installed. Every major DL architecture is implemented from scratch — no external DL dependencies required.

What's new in v0.3.0Module / Area
5-tier GPU dispatch (Triton → NumPy)vp.backend
50+ DL architectures: CNN, SSM, ViT, GAN, UNet, GNNvp.nn.architectures
Flash Attention — O(N) memory, causal maskingvp.nn.flash_attention
QAT — FakeQuantize, QATLinear/Conv2d, prepare/convertvp.nn.qat
Advanced optimizers: Lion, Sophia, Adan, Prodigyvp.nn.optimizers_advanced
BPE, WordPiece, SentencePiece tokenizers from scratchvp.tokenizers
Beam search, nucleus sampling, speculative decodingvp.text
Lightning-style Trainer + TrainableModelvp.trainer
RL: DQN, REINFORCE, A2C, PPO, SAC, TD3vp.rl
ONNX export + GGUF read/write (Q4_0, Q8_0)vp.export
Pretrained hub: load() + 20+ models, HF Hub compatiblevp.pretrained
Distributed: DataParallel, DDP, mixed precisionvp.distributed
16→41 modules, 110 Python filesvp (top level)

Installation

install.sh
pip install vectorphile                    # core (numpy + scipy)
pip install "vectorphile[viz]"              # + matplotlib
pip install "vectorphile[cuda]"             # + cupy (GPU via CuPy)
pip install "vectorphile[numba]"            # + numba CUDA kernels
pip install "vectorphile[triton]"           # + OpenAI Triton fused kernels
pip install "vectorphile[pretrained]"       # + safetensors, huggingface-hub
pip install "vectorphile[onnx]"             # + onnx, onnxruntime
pip install "vectorphile[rl]"               # + gymnasium
pip install "vectorphile[full]"             # all extras

# Requirements: Python >= 3.9, NumPy >= 1.24, SciPy >= 1.10

Quick Start

quickstart.py
import vectorphile as vp
from vectorphile.trainer import Trainer, TrainableModel
from vectorphile.data.datasets import MNIST

# 1. Data
train_ds, val_ds = MNIST(root='./data').split(val_ratio=0.1)

# 2. Model
class MyNet(TrainableModel):
    def __init__(self):
        super().__init__()
        self.net = vp.nn.Sequential(
            vp.nn.Linear(784, 256),
            vp.nn.GELU(),
            vp.nn.Linear(256, 10),
        )
    def forward(self, x):
        return self.net(x)
    def training_step(self, batch):
        x, y = batch
        loss = vp.nn.CrossEntropyLoss()(self(x), y)
        return loss

# 3. Train
trainer = Trainer(
    max_epochs=10,
    optimizer='adamw', lr=1e-3,
    callbacks=['early_stopping', 'model_checkpoint'],
    device='auto',
)
trainer.fit(MyNet(), train_ds, val_ds)

Tensors

vp.core

The Tensor is the central primitive. Set requires_grad=True for gradient tracking. Operations dispatch automatically to the fastest available backend.

tensor_ops.py
import vectorphile as vp

x = vp.randn(3, 4); y = vp.ones(4, 5)
z = x @ y                        # (3, 5) matmul

a = vp.zeros(5, 1) + vp.randn(1, 8)
b = a.reshape(5, 2, 4)
c = b.permute(2, 0, 1)

m = z.mean(); s = z.sum(axis=1, keepdims=True); mx, idx = z.max(axis=0)
x_f16 = x.astype('float16')
arr = x.numpy(); t = vp.from_numpy(arr)

Autograd

vp.autograd

Reverse-mode automatic differentiation. Dynamic computation graph supports arbitrary control flow. v0.3.0 adds jacobian, hessian, vmap, and gradient checkpointing.

autograd.py
x = vp.tensor([2.0, 3.0], requires_grad=True)
w = vp.tensor([[1.0, 0.5], [0.5, 1.0]])
h = x @ w
y = (h ** 2 + vp.log(h.abs() + 1)).sum()
y.backward()
print(x.grad)

from vectorphile.autograd import jacobian, hessian
J = jacobian(lambda v: (v ** 2).sum(), x)
H = hessian(lambda v: (v ** 2).sum(), x)

with vp.no_grad():
    logits = model(X_test)

Backend Dispatch

vp.backend

5-tier automatic dispatch selects the fastest available compute backend at runtime.

Tier 1
Triton
Fused CUDA kernels
Tier 2
PyTorch CUDA
Full GPU via cuBLAS
Tier 3
Numba CUDA
Custom GPU kernels
Tier 4
im2col+BLAS
CPU BLAS
Tier 5
NumPy
Pure Python fallback

Neural Networks

vp.nn

Complete neural network layer library. All operations support autograd.

LinearConv1d/2d/3dBatchNormLayerNormRMSNormDropoutEmbeddingRNNLSTMGRUMultiHeadAttentionTransformerSequentialModuleListModuleDictGroupNormInstanceNorm

Architecture Zoo

vp.nn.architectures

50+ production-grade DL architectures, all implemented from scratch with no external DL dependencies.

CNNs
  • →LeNet5
  • →VGG/11-19
  • →ResNet/18-152
  • →DenseNet
  • →MobileNetV2
  • →EfficientNet B0-B7
State Space Models
  • →S4 (HiPPO-LegT + FFT)
  • →Mamba (selective scan)
Vision Transformers
  • →ViT (tiny/small/base/large/huge)
  • →DeiT (distillation token)
Generative
  • →VAE (ELBO)
  • →DCGAN (gradient penalty)
  • →DDPM (cosine schedule)
Segmentation
  • →UNet
  • →ResUNet
  • →AttentionUNet (gated)
Graph Networks
  • →GCN
  • →GAT (multi-head)
  • →GraphSAGE
  • →GIN

Tokenizers

vp.tokenizers

All three major tokenization algorithms implemented from scratch.

BytePairEncodingWordPieceTokenizerSentencePieceTokenizer

Text Generation

vp.text
beam_searchnucleus_samplingspeculative_decodingTextGenerationPipeline
text_gen.py
from vectorphile.text import TextGenerationPipeline, beam_search, nucleus_sampling

pipe = TextGenerationPipeline(model=my_lm, tokenizer=bpe)
out = pipe("Once upon a time", max_new_tokens=100, strategy='nucleus', top_p=0.9)

# or call directly
ids = beam_search(logits_fn, start_ids, beam_width=4, max_len=200, no_repeat_ngram=3)
ids = nucleus_sampling(logits_fn, start_ids, top_p=0.95, temperature=0.8)

Trainer

vp.trainer

Lightning-style Trainer handles the training loop. Subclass TrainableModel and implement training_step().

trainer.py
from vectorphile.trainer import Trainer, TrainableModel

class MyModel(TrainableModel):
    def training_step(self, batch):
        x, y = batch
        return vp.nn.CrossEntropyLoss()(self(x), y)
    def validation_step(self, batch):
        x, y = batch
        return {'val_loss': vp.nn.CrossEntropyLoss()(self(x), y)}

trainer = Trainer(max_epochs=50, optimizer='adamw', lr=3e-4, device='auto')
trainer.fit(MyModel(), train_loader, val_loader)

RL Algorithms

vp.rl
DQNDoubleDQNDuelingDQNREINFORCEA2CPPOSACTD3PrioritizedReplayBuffer

ONNX Export

vp.export
onnx_export.py
from vectorphile.export import to_onnx, ONNXRuntime

to_onnx(model, dummy_input=vp.randn(1, 3, 224, 224), path='model.onnx')
rt = ONNXRuntime('model.onnx')
out = rt.run(input_array)

GGUF Format

vp.export
gguf.py
from vectorphile.export import to_gguf, from_gguf, GGUFReader, GGUFWriter

to_gguf(model, 'model.gguf', quantization='Q4_0')   # or Q8_0
model2 = from_gguf('model.gguf', model_cls=MyModel)

reader = GGUFReader('model.gguf')
writer = GGUFWriter('out.gguf')