β‘ Lightweight Deep Learning, high-performance tensor operations, gradient descent optimizers, and neural layers for the FastJava ecosystem.
FastDL is the Deep Learning engine of the FastJava ecosystem. While FastML focuses on classical, deterministic pattern models with hand-crafted features (Centroids, KNN, SVM), FastDL provides the neural substrate: Multidimensional Tensors, Automatic Differentiation / Backpropagation, Neural Layers (Dense, ReLU, Conv), Optimizers (SGD, Momentum, Adam), and Loss surfaces.
// Quick Start β Example
import fastdl.FastDL;
import fastdl.FastDL.Sequential;
import fastdl.loss.MSELoss;
import fastdl.optim.SGD;
import fastdl.tensor.Tensor;
public class Demo {
public static void main(String[] args) {
// 1. Define Multi-Layer Perceptron (MLP)
Sequential net = FastDL.sequential(
FastDL.dense(2, 8),
FastDL.relu(),
FastDL.dense(8, 1)
);
// 2. Setup Optimizer and Loss
SGD optimizer = FastDL.sgd(net.parameters(), 0.01f, 0.9f);
MSELoss criterion = FastDL.mse();
// 3. Forward Pass & Training Step
Tensor x = FastDL.tensor(new float[]{0.5f, -0.2f}, 1, 2);
Tensor target = FastDL.tensor(new float[]{1.0f}, 1, 1);
optimizer.zeroGrad();
Tensor pred = net.forward(x);
float loss = criterion.forward(pred, target);
net.backward(criterion.backward(pred, target));
optimizer.step();
System.out.printf("Loss: %.4f | Output: %s%n", loss, pred);
}
}- Why FastDL?
- Key Features
- API Quick Reference
- Installation
- Technical Examples & Hero Demos
- Documentation
- Platform Support
- License
- Related Projects
Standard Deep Learning frameworks in the Java ecosystem (like DL4J) suffer from bloated dependencies, complex native bridges, and heavy memory footprints.
FastDL delivers:
- 100% Pure JVM Core with Optional Native SIMD/GPU Acceleration β Instant startup, zero setup friction.
- Microsecond Tensor Operations β Cache-friendly flat arrays with stride-based multidimensional indexing.
- Zero Framework Bloat β Minimalist, PyTorch-like layer and optimizer APIs designed specifically for FastJava.
- Mini LLM / Transformer Foundations β including attention, feedforward blocks, embeddings, causal generation, and training loops.
- TinyStories-Ready Workflow β local datasets, tokenizer pipelines, and model training code built for small-language-model experimentation.
- π§± Dense & Multidimensional Tensors β Zero-copy flat buffers, strides, automatic gradient tracking (
grad). - π§ Neural Layers & Modular Sequentials β
Dense,ReLU,LayerNorm,GELU, and composable model blocks. - β‘ Optimizers with Momentum β Stochastic Gradient Descent and AdamW for transformer-style training.
- π Non-Convex Optimization & Loss Surfaces β Built-in loss metrics (
MSELoss,CrossEntropyLoss) and minima exploration. - π€ Mini Transformer / GPT-Style Stack β token embeddings, positional encoding, causal attention, feedforward blocks, and text generation.
- π TinyStories Demo Path β end-to-end local text-model demo workflow built around TinyStories-style corpora.
| Method | Description |
|---|---|
FastDL.tensor(shape...) |
Allocates a zero-initialized tensor. |
FastDL.dense(in, out) |
Creates a fully-connected linear layer. |
FastDL.relu() |
Rectified Linear Unit activation layer. |
FastDL.gelu() |
GELU activation (used inside Transformer FFN blocks). |
FastDL.layerNorm(dim) |
Pre-LayerNorm layer with learnable gamma/beta. |
FastDL.sequential(layers...) |
Chains layers into an executable network container. |
FastDL.sgd(params, lr, momentum) |
Creates an SGD optimizer with momentum. |
FastDL.adamW(params, lr) |
Creates an AdamW optimizer (standard for Transformers). |
FastDL.mse() |
Mean Squared Error loss. |
FastDL.crossEntropy() |
Cross-entropy loss for language modelling. |
| Method | Description |
|---|---|
FastDL.gptConfigSmall(vocabSize) |
GPT config: 128-dim, 4 heads, 4 layers, seqLen=128. |
FastDL.gptConfigMedium(vocabSize) |
GPT config: 256-dim, 4 heads, 6 layers, seqLen=256. |
FastDL.gpt(config) |
Creates a full causal GPT language model. |
FastDL.charTokenizer(corpus) |
Builds a character-level tokenizer from a text corpus. |
FastDL.trainerConfigDemo() |
Training config: 2 batch, 200 steps (runs in ~1 min on CPU). |
FastDL.trainerConfigStandard() |
Training config: 4 batch, 2000 steps with checkpointing. |
Add the JitPack repository and dependency to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastDL</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.andrestubbe:FastDL:0.1.0'
}| Case | Java Example | Launcher | Description |
|---|---|---|---|
| TinyStories Quick Preview | TinyStoriesMiniDemo.java | run-tiny-quick.bat |
Fast smoke test for TinyStories-style local text training. |
| TinyStories Transformer Smoke | TinyStoriesTransformerDemo.java | run-tiny-transformer.bat |
GPT-style mini transformer training run for quick validation. |
| TinyStories Big-Data Run | TinyStoriesTransformerDemo.java | run-tiny-big.bat |
Longer dataset-driven run intended for realistic local TinyStories experiments. |
| Non-Convex Loss Surface | LossSurfaceDemo.java | run-demo.bat |
Gradient descent and minima exploration on a shaped loss surface. |
| MLP Boundary Visualization | MLPBoundaryDemo.java | run-demo-mlp.bat |
Decision boundary demo for a small classification-style MLP. |
| Autoencoder / Representation Learning | AutoencoderDemo.java | run-demo-autoencoder.bat |
Lower-dimensional feature-learning demo for reconstruction tasks. |
The repo also includes simple Windows batch launchers for the demo flow:
run-demo.batβ generic project demo entrypointrun-demo-autoencoder.batβ autoencoder demorun-demo-mlp.batβ MLP demorun-tiny-quick.batβ Stage 1: TinyStories quick preview / smoke runrun-tiny-transformer.batβ Stage 2: TinyStories transformer smoke runrun-tiny-big.batβ Stage 3: long TinyStories big-data run- legacy aliases:
run-tiny.batandrun-tiny2.batdelegate to the new stage launchers
These launchers are designed to compile the root project, install the local artifact, and then execute the relevant example from the Java demo modules.
| Platform | Status |
|---|---|
| Windows 10/11 | β Fully Supported |
| Linux | β Fully Supported |
| macOS | β Fully Supported |
MIT License β See LICENSE for details.
- FastML β Classical Machine Learning and deterministic pattern recognition
- FastAI β High-level unified AI and reasoning substrate
- FastModel β Local GGUF/ONNX model runtimes
- FastGPU β Vulkan and GPU compute acceleration
Part of the FastJava Ecosystem β Making the JVM faster. Small package. Maximum speed. Zero bloat. π