ml_transformer is a lightweight, modular, and extensible machine learning and neural network library written in Dart.
- Tensor primitives and basic mathematical ops
- Common neural network layers (Embedding, Linear, LayerNorm, Attention, TransformerBlock)
- Mini autograd and AdamW optimizer
- Quantization helpers (int8, int4, int2, fp16, bf16)
- Basic ONNX import/export bridge (JSON demo; protobuf ONNX planned)
- Simple dataset loader and batching API
- Model save/load utilities
- Training callbacks and tracking (EarlyStopping, History)
- Unit tests covering core components
git clone <repo-url>
cd ml_transformer
dart pub get
import 'lib/dart_transformers.dart';
void main() {
final cfg = GPTConfig(
vocabSize: 256,
maxSeqLen: 128,
dModel: 64,
nHeads: 8,
nLayers: 4,
);
final model = GPTModel(cfg);
final logits = model.forward([1, 2, 3, 4]);
print('Logits: ${logits.rows} x ${logits.cols}');
}
There is also an example that demonstrates a tiny training loop, quantization and the ONNX import stub:
dart run example/demo_train_quant_onnx.dart
Run unit tests with:
dart test
- The ONNX bridge is a JSON-based demo; full ONNX (protobuf) support requires additional dependencies and parsing.
- Some layers (RNN / LSTM / GRU) are currently basic examples and may need optimization for production.
- Performance for very large models is limited by pure-Dart execution; native acceleration (FFI/GPU) is planned.
- Quantization utilities are intended as helpers and need calibration/validation for production models.
- Full ONNX protobuf import/export and weight mapping
- Complete and optimize RNN/LSTM/GRU implementations with tests
- Optional native acceleration (FFI / GPU backends)
- More quantization modes and calibration utilities
- High-level Model API (fit/predict/evaluate) with checkpoints and schedulers
Contributions are welcome. Please open issues or pull requests, and include tests for new functionality.
MIT