Gollek ML Framework Modules
This page replaces the older “SDK modules” view.
Gollek is moving toward a Gradle-only module layout with:
ml/*for the Java ML framework itselftrainer/*for training lifecycle and orchestrationintegration/*for JBang, Jupyter, LangChain4j, and other adapters
Older gollek-sdk-* names still appear in some examples and historical docs, but they should be treated as compatibility surfaces during the migration, not the canonical structure.
This page intentionally stays at /docs/sdk-modules.md so older links do not
break, but the content is now about the broader Gollek platform module naming,
not just the SDK layer.
Build and Install Path
For local development installs on macOS, use:
./run-install-local-macos.sh
This path now runs a Gradle-only install flow by default. Legacy Maven command fallback is intentionally removed from the default installer path to keep build behavior consistent.
Platform Naming Rules
Gollek should use distinct naming families for distinct responsibilities.
| Family | Canonical naming | Purpose |
|---|---|---|
| Inference and serving | gollek-backend-*, gollek-runner-*, gollek-plugin-runner-*, gollek-provider-*, gollek-spi-* |
runtime engine, hardware adapters, format runners, serving contracts |
| Client and application SDK | gollek-sdk-* |
application-facing SDKs, sessions, local/remote client access |
| Java ML framework | gollek-ml-* |
model building, data, optimization, export, hub, framework utilities |
| Trainer | gollek-trainer-* |
training lifecycle, experiment orchestration, trainer runtime contracts |
| Integrations | gollek-integration-* |
JBang, Jupyter, LangChain4j, and other adapters |
That split matches the Gollek vision:
- inference/serving is the core identity
- Java ML/training is a first-class framework layer
- SDKs and integrations are adapters around those cores, not the core itself
Inference and Serving
For the serving side, prefer these naming patterns:
backend/*- hardware-specific acceleration surfaces such as Metal, CUDA, ROCm, Vulkan
runner/*- model-format execution adapters such as GGUF, Safetensor, ONNX, LiteRT
provider/*andspi/*- provider routing and runtime contracts
sdk/*- application-facing client access, not the ML framework itself
Architecture naming should also stay explicit:
native-java- preferred long-term path where Gollek handles execution in Java directly
binding- short-term compatibility and fallback path for llama.cpp, libtorch, LiteRT, ONNX runtime, and similar native bridges
For mobile and portable library usage, the most natural naming surfaces are:
:runner:onnx:*:runner:litert:*
Those are the right places to emphasize Quarkus/GraalVM portability and platform-specific delivery.
Canonical Layout
Core ML Framework
| Canonical Gradle module | Role |
|---|---|
:ml:gollek-ml-api |
umbrella framework entrypoint |
:ml:gollek-ml-core |
shared estimator and transformer foundations |
:ml:gollek-ml-selection |
metrics, cross-validation, model selection |
:ml:gollek-ml-data |
dataset and dataloader APIs |
:ml:gollek-ml-diffusion-api |
diffusion-training contracts for Java task, prompt, scheduler, and session APIs |
:ml:gollek-ml-diffusion-opd |
Java implementation scaffold for DiffusionOPD-style multi-task distillation |
:ml:gollek-ml-runner-api |
runner abstraction for ONNX, LiteRT, and future adapters |
For diffusion alignment, Gollek now exposes a Java-first OPD surface described in:
Current public training data and metric conveniences live behind
tech.kayys.gollek.ml.Gollek.DL:
TrainingPreset.REGRESSION_HUBER_*,huberLoss(...), andtrainingOptions().regressionMetrics()support outlier-tolerant regression with MAE, MSE, RMSE, and R2 reporting.trainingOptions().checkpointDir(...).restoreBestModelAtEnd()saves validation-driven best-model snapshots tocanonical-best-model.safetensorsand reloads the best epoch before returning. By default the monitor is validation loss, but.bestModelMonitorMetric("f1", BestModelMonitorMode.MAX)can select by a named validation metric such as F1, accuracy, AUROC, or average precision.trainingOptions().earlyStopping(...).earlyStoppingMonitorMetric(...)uses the same validation metric stream to stop by task quality, so classification runs can stop on F1 or AUROC while regression runs keep the validation-loss default.TrainingSummary.metadata().get("epochHistory")gives one row per completed epoch with train/validation losses, metric values, learning rate, optimizer steps, and scheduler steps for dashboards and reproducible debugging.trainingOptions().stepLrBatches(...),.cosineAnnealingLrBatches(...),.warmupCosineLrBatches(...), and theirEpochsvariants expose public scheduler policies for one-callfit(...). Warmup/cosine starts new runs at LR0.0, supports scheduler checkpoint resume, and reportslearningRateSchedulerState.*metadata.trainingOptions().reduceLrOnPlateauValidationLoss(...)lowers LR when validation loss stalls, while.reduceLrOnPlateauMetric(...)can follow a named validation metric. Plateau state is checkpointed and reported throughlearningRateSchedulerState.*.- Summary and history metadata include gradient/parameter diagnostics such as
latestGradientL2NormBeforeClip,latestGradientL2Norm,latestGradientClipped, andlatestParameterL2Norm, making exploding or clipped gradients visible in ordinary SDK runs. - The trainer has a non-finite guard for NaN/Inf loss and gradients. It fails
before unsafe backward/optimizer updates, clears pending gradients, avoids
writing corrupted checkpoints, and reports
nonFinite*metadata plus astopReasonsuch asnon-finite-train-loss. - Summary and history metadata also include train/validation throughput
counters such as
trainBatchCount,trainSampleCount,trainSamplesPerSecond,validationBatchCount, andvalidationSamplesPerSecond. - When
checkpointDir(...)is set, the same history is persisted ascanonical-history.csvbeside the checkpoint files for spreadsheet-friendly learning-curve inspection. Resumed runs reload existing rows and append new epochs so interrupted training keeps a continuous curve. Nested metric maps and detailed diagnostics are encoded as deterministic JSON cells, so dashboards can parse confusion matrices and similar payloads without scraping JavaMap.toString()text. Malformed structured cells are surfaced throughtrainingHistoryLoadErrorand rejected by strict resume. Duplicate headers, blank headers, and rows with extra cells are treated as ambiguous history shape errors instead of being silently overwritten or ignored. Theepochcolumn is required and must contain unique non-negative integers. - The checkpoint directory also receives
canonical-report.json, a structured trainer report with final summary fields, epoch history, metric maps, checkpoint state, accelerator metadata, gradient diagnostics, and throughput counters for CLIs, dashboards, and JBang examples. - Optimizer checkpoints now preserve SGD momentum, Adam/AdamW moments, and
RMSprop accumulators/velocity so
resumeFromCheckpoint()can continue optimizer dynamics instead of only restoring model weights. - Optimizers and
GradientClippernow validate finite hyperparameters, parameter values, and gradients before mutating state. Adam L2 weight decay leaves gradient buffers intact, and Adagrad applies weight decay uniformly across the full tensor. - StepLR, CosineAnnealingLR, WarmupCosineScheduler, and ReduceLROnPlateau now validate finite scheduler configuration and checkpoint payloads before restoring resumed learning rates, rejecting NaN LRs, negative counters, and infinite plateau metrics.
- Trainer summaries now expose partial-resume diagnostics for checkpoint
artifacts, so users can see whether model, optimizer, scheduler, GradScaler,
or history files were missing when resume began even if the run recreates
them later. Strict resume now fails closed on missing runtime state or
required artifacts, while lenient loading records
checkpointResumePartialand the missing names. - Model checkpoints now write
canonical-model.metadatabesidecanonical-model.safetensors. Resume validates model class and parameter signatures plus byte-size/SHA-256 integrity when metadata exists, fails fast by default on incompatible or corrupted snapshots, and recordscheckpointResumeCompatibilityMismatcheswhen lenient checkpoint loading is explicitly enabled. - Checkpoint directories now also write
canonical-checkpoints.metadata, a byte-size/SHA-256 manifest for runtime, optimizer, scheduler, GradScaler, history, report, and model artifacts. Resume validates runtime-state files before deserializing them, so corrupted runtime/optimizer/scheduler state fails closed by default and is reported through lenient compatibility diagnostics. Best-model restore-at-end uses the same manifest guard before replacing current weights. - Train and validation batches now validate non-null, non-empty, sample-aligned, finite input/label tensors before forward or loss execution, so malformed or NaN/Infinity dataset values fail before they can poison gradients, optimizer state, or validation metrics.
- Custom trainer loss functions must return a single-value tensor. Vector or
matrix losses now fail before
backward(), surfacinginvalidLossShapeinstead of logging one value while autograd propagates another reduction. - Trainer model outputs are validated before loss and metric evaluation, so
NaN/Infinity predictions fail as
nonFiniteKind=predictioninstead of leaking into custom losses or validation metrics. - Trainer metric snapshots now validate finite values after real
train/validation batches have run. Duplicate names, NaN/Infinity, or throwing
custom metrics stop the run, and
DetailedMetricpayloads are guarded the same way. Failures reportinvalidMetric*metadata and skip final checkpoint writes, while empty train/validation phases may remain undefined for compatibility. - Trainer metric contracts are now standalone
TrainingMetricandDetailedTrainingMetricAPIs, withTrainingMetricsas the public built-in catalog. Built-ins are split internally by regression, binary, multiclass, and multilabel metric families. The legacyCanonicalTrainer.Metric,.DetailedMetric, and.Metricsnames remain as compatibility aliases instead of owning the implementation. QuantizationEnginenow uses real supplied weights: either direct in-memory tensors or a simple text weight file. Missing model files fail fast instead of generating placeholder weights, and the output artifact includes quantized codes, dequantized values, compression estimates, and error metrics.GradScalernow performs real mixed-precision loss scaling: callers backpropagate the returned scaled loss, unscale optimizer/parameter gradients, skip unsafe steps on NaN/Inf, and let the scale grow/back off from observed overflow. The scaler can now be checkpointed/resumed with compatibility validation and overflow-safe unscale writes.CanonicalTrainer.Builder.mixedPrecision(true),.gradScaler(...), andtrainingOptions().mixedPrecision()now use that scaler during the actual trainer step. PublictrainingOptions().gradScaler(customScaler)/.mixedPrecision(customScaler)can tune the initial scale and growth policy, while overflowed updates are skipped andcanonical-grad-scaler.statepersists scaler state for resume. Incompatible saved scaler policies fail closed by default, with opt-in lenient loading surfacing the mismatch in trainer metadata andgradScalerCheckpointFallbackUsed.GradTensornow differentiates common composed training graphs including view ops,sum/mean,pow, unary math/activation ops, and last-dimensionsoftmax, so custom Java losses can rely on autograd instead of manual hooks for basic expressions.Gollek.cat(...),Gollek.stack(...), andGollek.where(...)now keep autograd links alive through concatenation, stacking, and broadcasted selection paths.- Transformer attention compatibility einsums (
bhid,bhjd->bhijandbhij,bhjd->bhid) now keep gradients connected through attention score and context application paths for Java-side transformer training. - Public
MultiHeadAttentionkeeps gradients through head split/merge reshapes and causal masks, andTransformerBlockdropout now applies a differentiable mask instead of returning detached tensors. FlashAttentionuses differentiable exact attention when gradients are tracked, while the no-grad tiled inference path keeps its memory-efficient loop and correctly merges multi-head output order.MultiHeadAttention(..., dropoutP)now applies attention-probability dropout after softmax, and transformer encoder/decoder layers pass their dropout setting into internal self/cross attention modules.TransformerBlocknow uses a registered GELU feed-forward activation, so the implementation matches the documented transformer FFN instead of silently behaving like a ReLU block.RotaryEmbedding.apply(...)now keeps RoPE gradients connected via the inverse rotation and validates rank, head dimension, and max sequence length before using the frequency cache.- Root
tech.kayys.gollek.ml.nn.GroupNormnow preserves gradients through differentiable reshape/mean/variance tensor ops and validates group/channel configuration before training. Dropoutnow rejects non-finite probabilities and handlesp=1as an explicit zero-output/zero-gradient path, while layerGroupNormvalidates group counts, epsilon, rank, and channel count.- Weighted
CrossEntropyLossnow uses sample-weight mean normalization for both scalar loss and logits gradients instead of scaling by raw batch size. - CrossEntropy, Focal, LabelSmoothing, ArcFace, and CTC losses now validate
class-index targets so wrongly-shaped,
NaN, fractional, or out-of-range labels fail before training indexes logits. - CrossEntropy, LabelSmoothing, BCE-with-logits, and focal losses now reject
non-finite logits before softmax/sigmoid loss computation, preventing bad
activations from entering the trainer graph as silent
NaNgradients. FocalLossandBinaryFocalWithLogitsLossnow reject empty or non-finite logits before focal weighting, with finite-difference coverage for positive-weighted binary/multi-label focal gradients.- Regression losses (
MSELoss,L1Loss,SmoothL1Loss,HuberLoss) now reject empty tensors and NaN/Inf predictions or targets before loss/gradient computation, andSmoothL1Lossuses standard beta-scaled semantics. LabelSmoothingLossnow keeps gradients connected with the standardsoftmax - smoothedTargetbackward path for calibrated classification training.BCEWithLogitsLossnow uses a stable softplus formulation, preserving large losses for confident wrong binary predictions and rejecting non-finite logits or invalid targets before training.DiceLossnow backpropagates the overlap objective for segmentation training and validates probability predictions, binary masks, matching shapes, and smoothing values.IoULossnow backpropagates through predicted bounding boxes and validates[batch, 4]finite, ordered coordinates before computing object-detection overlap loss.TripletLossnow backpropagates active margin violations to anchor, positive, and negative embeddings and validates matching[batch, dim]embedding tensors.ContrastiveLossnow backpropagates positive pairs and active negative margin violations while validating binary labels and matching[batch, dim]embedding tensors.CosineEmbeddingLossnow backpropagates positive and active negative cosine pairs while validating strict1.0/-1.0labels, margin bounds, and matching[batch, dim]embedding tensors.CTCLossnow backpropagates log-probability inputs using log-space forward-backward posteriors and rejects blank/impossible target alignments before training.ArcFaceLossnow backpropagates through feature embeddings and learned class centers, including normalization and angular-margin derivatives.KnowledgeDistillationnow trains student models from both soft teacher distributions and hard labels using teacher-to-student KL plus CrossEntropy, with teacher logits detached and student gradients preserved.- The default CPU NN backend now implements depthwise convolution, image resize/crop/normalize, scaled dot-product attention, and multi-head attention instead of returning null for these runtime paths.
classificationDataLoader(...)andclassificationTrainValidationSplit(...)accept Javaint[]labels and produce CrossEntropy-compatible class-index tensors.classificationStratifiedTrainValidationSplit(...)andbinaryStratifiedTrainValidationSplit(...)preserve class/binary label coverage across train and validation sets for small classification datasets.multiLabelBinaryStratifiedTrainValidationSplit(...)balances per-label positive counts while preserving exact train/validation sizes for multi-label BCE datasets.trainingOptions().classificationMetrics()records accuracy, macro precision, macro recall, and macro F1 intoTrainingSummary.metadata().confusionMatrixMetric()/trainingOptions().confusionMatrixMetric()records scalarconfusion_matrix_accuracyplus structured matrix details in summary metadata, epoch history,canonical-history.csv, andcanonical-report.json. Rows represent actual classes and columns represent predicted classes.trainingOptions().topKAccuracyMetric(k)records top-k accuracy, such astop2_accuracyortop5_accuracy, for logits shaped[batch, classes].classificationMacroRocAucMetric(),classificationMacroAveragePrecisionMetric(), andtrainingOptions().classificationRankingMetrics()report one-vs-rest multi-class ranking quality directly from CrossEntropy-style logits.classWeights(...)derives balanced weights for imbalanced multi-class datasets,classWeightsFor(numClasses, ...)supports explicit class counts, andtrainingOptions().crossEntropyClassWeights(...)applies those weights to the one-call CrossEntropy trainer preset path.TrainingPreset.CLASSIFICATION_FOCAL_*,focalLoss(...), andtrainingOptions().focalGamma(...)/.focalClassWeights(...)support focal-loss classification for hard-example-focused imbalanced training, with finite-logit validation before softmax/focal weighting.TrainingPreset.BINARY_FOCAL_WITH_LOGITS_*,binaryFocalWithLogitsLoss(...), andtrainingOptions().focalGamma(...)/.focalAlpha(...)combine focal hard-example weighting with existing.bcePositiveWeight(...)/.bcePositiveWeights(...)controls for imbalanced binary and multi-label training, with finite-logit validation and tested positive-weight gradients.binaryDataLoader(...),binaryTrainValidationSplit(...),binaryStratifiedTrainValidationSplit(...), andTrainingPreset.BINARY_BCE_WITH_LOGITS_*support one-output binary classifiers using BCE-with-logits targets shaped[batch, 1].binaryPositiveWeight(...)derivesnegatives / positivesfor imbalanced binary datasets, andtrainingOptions().bcePositiveWeight(...)applies it to the one-call BCE trainer preset path.trainingOptions().binaryClassificationMetrics()records thresholded binary accuracy, precision, recall, and F1 using logit0.0as the probability0.5boundary.binaryAccuracyMetric(logitThreshold),binaryF1Metric(logitThreshold), andtrainingOptions().binaryClassificationMetrics(logitThreshold)evaluate binary BCE/focal logits at deployment-specific operating points.binaryConfusionMatrixMetric(logitThreshold)andtrainingOptions().binaryConfusionMatrixMetric(logitThreshold)record scalarbinary_confusion_matrix_accuracyplus TN/FP/FN/TP, specificity, balanced accuracy, and a structured[[TN, FP], [FN, TP]]matrix in trainer summaries, evaluation summaries, epoch history, and reports.binaryRocAucMetric(),binaryAveragePrecisionMetric(), andtrainingOptions().binaryRankingMetrics()report ranking quality directly from logits for imbalanced binary datasets.multiLabelBinaryDataLoader(...),multiLabelBinaryTrainValidationSplit(...), andmultiLabelBinaryStratifiedTrainValidationSplit(...)accept Javaint[][],boolean[][], orfloat[][]targets while preserving[batch, labels]shape for multi-label BCE training.multiLabelPositiveWeights(...)derives per-label imbalance weights, andtrainingOptions().bcePositiveWeights(...)applies those weights to multi-label BCE-with-logits presets.trainingOptions().multiLabelBinaryMetrics()records exact-match accuracy, Hamming loss, macro precision, macro recall, and macro F1 for multi-label BCE outputs.multiLabelMacroF1Metric(logitThreshold)andtrainingOptions().multiLabelBinaryMetrics(logitThreshold)evaluate multi-label BCE/focal logits with custom thresholds when probability0.5is not the desired operating point.multiLabelMacroRocAucMetric(),multiLabelMacroAveragePrecisionMetric(), andtrainingOptions().multiLabelRankingMetrics()report per-label macro ranking quality directly from multi-label logits.evaluate(...)runs no-grad validation/test passes with the same metric factories used by training.
Trainer
| Canonical Gradle module | Role |
|---|---|
:trainer:gollek-trainer-api |
trainer contracts such as config, session, listeners, summaries |
:trainer:gollek-trainer |
canonical trainer runtime facade (module path: trainer/gollek-trainer) |
training/gollek-train (legacy source area) |
compatibility source area while migration continues; new Gradle runtime module is :trainer:gollek-trainer |
Deployment and Model Distribution
| Canonical Gradle module | Role |
|---|---|
:ml:gollek-ml-hub |
pretrained model discovery and loading |
:ml:gollek-ml-export |
export and benchmarking |
:runner:onnx:gollek-ml-export-onnx |
ONNX export bridge |
Public API Direction
For new framework code, prefer:
tech.kayys.gollek.ml.Gollektech.kayys.gollek.ml.vision.*tech.kayys.gollek.ml.optimize.*
For trainer lifecycle contracts, prefer:
tech.kayys.gollek.trainer.api.*tech.kayys.gollek.trainer.*
For client/application SDK code, prefer:
tech.kayys.gollek.sdk.*tech.kayys.gollek.sdk.feature.*for ML Kit-style app features
For compatibility during the migration, these older namespaces are still intentionally bridged:
tech.kayys.gollek.train.*tech.kayys.gollek.export.*tech.kayys.gollek.hub.*
Those compatibility namespaces exist so older code and examples do not break while the canonical ml/* and trainer/* structure settles.
Quick Start
ML Kit-Style SDK Features
Gollek SDK now exposes a grouped feature kit for app-facing capabilities:
- Face recognition
- Natural language
- Document scanner
Preferred entrypoint:
import tech.kayys.gollek.sdk.feature.GollekFeatureKit;
GollekFeatureKit features = sdk.featureKit();
Recommended package direction:
tech.kayys.gollek.sdk.feature.GollekFeatureKittech.kayys.gollek.sdk.feature.*request/response types
For local runtime usage through gollek-sdk-local, these features route through:
- multimodal processors when available (vision/doc pipelines)
- local heuristic NLP fallback for language/sentiment/entity extraction
ML Framework Entry Point
import tech.kayys.gollek.ml.Gollek;
import tech.kayys.gollek.ml.vision.models.ResNet;
ResNet model = ResNet.resnet18(10);
var exporter = Gollek.Export.model(model)
.inputShape(1, 3, 224, 224)
.build();
exporter.toONNX("model.onnx");
Model Hub
import tech.kayys.gollek.ml.Gollek;
import tech.kayys.gollek.ml.vision.models.ResNet;
ResNet model = ResNet.resnet18(1000);
Gollek.Hub.loadInto(model, "hf:google/vit-base-patch16-224");
Compatibility Example
If you still have older code that imports the legacy compatibility bridge:
import tech.kayys.gollek.export.ModelExporter;
import tech.kayys.gollek.hub.ModelHub;
that is still supported for now, but new code should move toward Gollek.Export, Gollek.Hub, and tech.kayys.gollek.ml.*.
Migration Map
| Legacy wording | Current canonical meaning |
|---|---|
gollek-sdk-train |
trainer runtime split across :trainer:gollek-trainer-api, :trainer:gollek-trainer, plus legacy compatibility sources under training/gollek-train |
gollek-sdk-export |
:ml:gollek-ml-export plus Gollek.Export and tech.kayys.gollek.export.* compatibility |
gollek-sdk-hub |
:ml:gollek-ml-hub plus Gollek.Hub and tech.kayys.gollek.hub.* compatibility |
gollek-sdk-core |
shared ML/tensor/autograd foundations now spread across gollek-ml-api, gollek-ml-core, gollek-ml-tensor, and gollek-ml-autograd |
gollek-sdk-local |
local application/client SDK, not the canonical ML framework root |
gollek-sdk-session |
session/client compatibility surface; trainer contracts now belong under gollek-trainer-* |
JBang Examples
The repository still contains JBang files whose names start with gollek-sdk-*.
That does not mean the old SDK naming is the preferred future direction.
Those files are kept for continuity while the public ML framework surface is migrated. Canonical trainer-aligned examples now start with:
gollek/examples/jbang/trainer/trainer_runtime_bootstrap.javagollek/examples/jbang/trainer/trainer_accelerated_autograd.javagollek/examples/jbang/trainer/trainer_resume_history.javagollek/examples/jbang/trainer/trainer_robust_regression_huber.javagollek/examples/jbang/trainer/trainer_classification_metrics.javagollek/examples/jbang/trainer/trainer_binary_bce_metrics.javagollek/examples/jbang/trainer/trainer_multilabel_bce_metrics.java
Before running those trainer examples from gollek/examples/jbang, publish
their local Gradle-built runtime graph with:
./gradlew publishJbangTrainerExamplesToMavenLocal
Compatibility examples under older SDK naming include:
gollek/examples/jbang/sdk/gollek-quickstart.javagollek/examples/jbang/sdk/gollek-sdk-core-example.javagollek/examples/jbang/sdk/gollek-sdk-vision-example.javagollek/examples/jbang/sdk/gollek-sdk-train-example.javagollek/examples/jbang/sdk/gollek-sdk-augment-example.javagollek/examples/jbang/sdk/gollek-sdk-export-example.java
should be read as compatibility samples during the rename, not as the final naming model.