GLiNER2 fine-tuning: Zig-native LoRA training at result parity with upstream - #377
Open
timkaye11 wants to merge 15 commits into
Open
GLiNER2 fine-tuning: Zig-native LoRA training at result parity with upstream#377timkaye11 wants to merge 15 commits into
timkaye11 wants to merge 15 commits into
Conversation
timkaye11
marked this pull request as draft
July 21, 2026 16:23
The function was defined twice in tier/memory.zig, so the branch tip did not compile. Drop the redundant copy; the surviving definition above is identical.
timkaye11
force-pushed
the
gliner2_finetuning_party
branch
from
August 3, 2026 19:41
78b12ff to
5b2cd16
Compare
timkaye11
marked this pull request as ready for review
August 3, 2026 21:17
timkaye11
force-pushed
the
gliner2_finetuning_party
branch
from
August 4, 2026 05:47
12e96c3 to
acd3037
Compare
timkaye11
force-pushed
the
gliner2_finetuning_party
branch
from
August 4, 2026 17:22
63b6554 to
5837769
Compare
timkaye11
force-pushed
the
gliner2_finetuning_party
branch
from
August 4, 2026 19:52
5837769 to
a2e5a96
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds end-to-end GLiNER2 LoRA fine-tuning to Antfly’s Zig inference stack, including full-task training, native and Metal execution, checkpoint/resume, evaluation, adapter materialization, and deterministic parity validation against fastino-ai/GLiNER2.
The implementation supports entities, classifications, JSON structures, relations, and count supervision through the
gliner2-total-lossobjective.What’s included
Training and data pipeline
alpha / rankscaling, inverted dropout, and deterministic initialization.[DESCRIPTION],[EXAMPLE], and[OUTPUT].Runtime and artifacts
antfly inference finetune.See GLINER2.md for the operator and release contract.
Fastino parity
The correctness oracle is a pinned upstream Fastino GLiNER2 checkout running under the locked Python 3.12 environment.
2e-71e-4absolute +5e-6relative8/8fixtures0mismatches2.97e-3(<= 6e-3)3/3objectives4e-6(<= 1e-3)The eight-fixture matrix covers entity extraction, classification, JSON structures, relations, mixed full-task records, repeated instances, all-negative classification, descriptions, and few-shot examples.
Metal parity additionally requires real GPU dispatches, the Metal optimizer path, zero trainable device-transfer fallbacks, finite losses, and no graph-executor fallback reasons.
Local real-model validation
Validated locally against the complete
fastino/gliner2-base-v1model bundle:255/25543/43passed2/2passed1.799863 -> 1.55947413.4%0.24933620.804317, grad norm8.8604The full-task smoke deliberately introduces one misclassified binary target because the pretrained model solves every supervised cell in the tiny fixture with margins above
20, causing the unmodified f32 BCE and gradient to saturate to zero. This keeps the test focused on proving a real backward/update path.Performance
Diagnostic three-step configuration: batch
2, sequence length64, LoRA rank4.0.20 s0.55 s15 sThe native backend is the correctness reference. Performance qualification targets compiled Metal at production shapes—batch
32, sequence length128—with five repeated runs, a warm-step median no slower than the Python baseline, no individual run above1.10x, and a3 GiBdevice-owned peak-live ceiling.Scope
Parity covers the deterministic training core: preprocessing, losses, gradients, optimizer behavior, parameter updates, and artifact interoperability. Exact reproduction of upstream PyTorch RNG traces—shuffle order, dropout masks, stochastic negative masking, and augmentation sampling—is intentionally outside the contract.
The local model run proves that the complete checkpoint can train, update, save, and reload through the Zig stack. It is not a held-out quality benchmark. Final release qualification remains artifact-driven and requires representative disjoint train/eval data, all nine held-out quality floors, five paired independent Fastino/Zig training seeds, and production-shape Metal performance evidence.