PML Framework Docs
Documentation

PML Framework

A high-performance machine learning framework for PHP 8.2+.
All tensor math runs in a C engine (libtensor.so) via FFI — PHP orchestrates, C computes. OpenBLAS + AVX2 + OpenMP + LAPACKE. No Python. No ONNX. No wrappers.

Architecture

┌─────────────────────────────────────────────────────────────────────────┐ │ PHP Application │ │ Pipeline · Sequential · Trainer · InferenceSession · AutoML │ └───────────────────────────────┬─────────────────────────────────────────┘ │ PHP FFI (zero-copy Tensor* handles) ┌───────────────────────────────▼─────────────────────────────────────────┐ │ TensorEngine.php │ │ Singleton cdef bridge ─ TensorFFI ─ QuantEngine ─ VisionEngine │ └──┬─────────────────┬─────────────────┬──────────────────────────────────┘ │ │ │ ▼ ▼ ▼ libtensor.so.7 libquant.so.1 libvision.so tensor.c quant.c 8 C files dataset_io.c (INT8 AVX2) (106 vision ops) inference.c autograd.c graph.c tokenizer.c OpenBLAS · LAPACKE · AVX2/AVX512 · OpenMP

Key Properties

Zero-Copy FFI

PHP holds TensorC* C pointers. No PHP-side float arrays. All math crosses the FFI boundary once per operator.

OpenBLAS + AVX2

GEMM via OpenBLAS. Element-wise ops via 256-bit AVX2 SIMD. OpenMP multi-threading. LAPACKE for SVD/eigendecomp.

INT8 Quantization

Dense layers quantize to INT8 block format (Q8_0). 4× memory reduction. AVX2 fused int8→fp32 dot kernel. 7B model in ~7 GB RAM.

KV-Cache

Multi-head KV cache for autoregressive decode. Milakov online-softmax. O(1) decode per token vs O(T²) recompute.

SafeTensors I/O

HuggingFace-compatible checkpoint format. mmap()-backed zero-copy weight loading. No PHP serialize().

Full ML Stack

19 classifiers · 15 regressors · 6 anomaly detectors · 5 clusterers · 44 transformers · 29 NN layers · Vision module.

Documentation Pages

Namespace Map

NamespaceLocationDescription
Pml\src/Root: Tensor, Dataset, DataFrame, Pipeline, Arena, QuantizedTensor
Pml\Estimators\Classifiers\src/Estimators/Classifiers/19 classification estimators
Pml\Estimators\Regression\src/Estimators/Regression/15 regression estimators
Pml\Estimators\AnomalyDetectors\src/Estimators/AnomalyDetectors/6 anomaly detectors
Pml\Estimators\Clusterers\src/Estimators/Clusterers/5 clustering algorithms
Pml\Transformers\src/Transformers/44 data transformers
Pml\NeuralNetwork\src/NeuralNetwork/Sequential, layers, optimizers, activations, initializers
Pml\Losses\src/Losses/Loss functions
Pml\Training\src/Training/Trainer, LRScheduler, GradScaler, callbacks
Pml\Inference\src/Inference/InferenceSession, ModelConfig, Tokenizer
Pml\Vision\src/Vision/Image, detection, segmentation, augmentation, models
Pml\Interfaces\src/Interfaces/15 contracts used across the framework
Pml\Lib\src/Lib/TensorEngine, QuantEngine, VisionEngine, Arena, ModelStore, SafeTensorsIO
Pml\Autograd\src/Autograd/Variable, Tape — automatic differentiation

Interface Hierarchy

Estimator └─ Learner (train + predict) └─ TrainableWithOptions (named-arg variadic options) └─ Transformer (fit + transform + fitTransform) └─ Probabilistic (predictProba) └─ Scoring (score) └─ Online (partial_fit — streaming) └─ RanksFeatures (featureImportances) └─ Verbose (setLogger) └─ Persistable (save + load) └─ Stateful (getStateDict + loadStateDict) └─ Saveable (getConfig + fromConfig) └─ Quantizable (quantize + isQuantized) └─ FitTransformable (fitTransform shortcut)