Gravicode.HFNet.GraviAccelerate
0.1.0
See the version list below for details.
dotnet add package Gravicode.HFNet.GraviAccelerate --version 0.1.0
NuGet\Install-Package Gravicode.HFNet.GraviAccelerate -Version 0.1.0
<PackageReference Include="Gravicode.HFNet.GraviAccelerate" Version="0.1.0" />
<PackageVersion Include="Gravicode.HFNet.GraviAccelerate" Version="0.1.0" />
<PackageReference Include="Gravicode.HFNet.GraviAccelerate" />
paket add Gravicode.HFNet.GraviAccelerate --version 0.1.0
#r "nuget: Gravicode.HFNet.GraviAccelerate, 0.1.0"
#:package Gravicode.HFNet.GraviAccelerate@0.1.0
#addin nuget:?package=Gravicode.HFNet.GraviAccelerate&version=0.1.0
#tool nuget:?package=Gravicode.HFNet.GraviAccelerate&version=0.1.0
HF.Net
A Hugging Face style machine learning ecosystem for .NET.
Load a real model from the Hugging Face Hub, tokenize exactly the way it was trained, and run it — all from C#, with no Python in the loop.
using var model = TransformerModel.Load("bert-base-uncased");
foreach (var fill in model.FillMask("The capital of France is [MASK].", topK: 3))
Console.WriteLine($"{fill.Token,-10} {fill.Score:P2}");
// paris 41.53 %
// lille 7.16 %
// lyon 6.31 %
Built on Gravicode.Science
— GraviNum (arrays), GraviFrame (dataframes) and GraviLearn (classical ML).
Dibuat oleh Gravicode Studios, dipimpin oleh Kang Fadhil.
Documentation: English · Bahasa Indonesia
The libraries
Each mirrors a package in the Python Hugging Face stack.
| Library | Mirrors | What it does |
|---|---|---|
| GraviHub | huggingface_hub |
Hub download and upload, a readable local cache, and readers for the formats the Hub serves: safetensors and pytorch_model.bin |
| GraviTokenizers | tokenizers |
WordPiece, byte-level BPE and Unigram, loading tokenizer.json — with character offsets that point back into the original text |
| GraviDatasets | datasets |
CSV, Parquet, JSON and JSON Lines, Hub datasets, splits, streaming and memory-mapped reads |
| GraviTransformers | transformers |
Load pretrained BERT-family encoders and run them: classification, fill-mask, embeddings, similarity |
| GraviPEFT | peft |
LoRA adapters in the Hugging Face PEFT format — apply, merge, save, load |
| GraviAccelerate | accelerate |
Device selection across CPU SIMD and ILGPU, sharding, weighted gradient averaging, honest throughput measurement |
| GraviOptimum | optimum |
ONNX Runtime inference with an explicitly chosen execution provider, and weight quantisation that reports its measured error |
| GraviDiffusers | diffusers |
DDPM, DDIM and Euler schedulers, and a Stable Diffusion text-to-image pipeline over ONNX |
Gravicode.Science ──► GraviHub ──┬──► GraviTokenizers ──┐
GraviNum ├──► GraviDatasets ├──► GraviTransformers ──┬──► GraviPEFT
GraviFrame └──► GraviOptimum ─────┘ └──► GraviDiffusers
GraviLearn GraviAccelerate
Getting started
git clone <this repository>
cd HF.Net
dotnet build HF.Net.sln -c Release
dotnet run --project samples/GraviTransformers.Console -- bert-base-uncased
Set HF_TOKEN for private or gated repositories, and for a much higher anonymous rate limit.
Downloads land in the same cache the Python tooling uses (HF_HUB_CACHE, then HF_HOME), so the
two share a machine without duplicating a single checkpoint.
What it can do today
Reads both weight formats the Hub serves. safetensors is memory-mapped and read lazily, so
listing four hundred tensors costs a header read rather than a multi-gigabyte load. The many
repositories that only ever published pytorch_model.bin work too — the pickle is interpreted
against an allow-list of tensor constructors, so nothing in the file is executed.
Tokenizes identically to the reference implementation. bert-base-uncased on
"Hello, world! Tokenizers are unbelievable." produces
[CLS] hello , world ! token ##izer ##s are unbelievable . [SEP] with ids
101 7592 1010 2088 999 19204 17629 2015 2024 23653 1012 102 — the same ids Python gives.
Runs real models. Verified against bert-base-uncased (fill-mask),
distilbert-base-uncased-finetuned-sst-2-english (classification: 99.99% POSITIVE on
"I absolutely loved this film.") and prajjwal1/bert-tiny (a pickle-only checkpoint).
What it cannot do yet
Stated plainly, because a library that fails quietly is worse than one that says no:
- Decoder-only models — GPT, Llama, Mistral — are refused, not half-loaded. They need causal masking and rotary positions this encoder does not have.
- LoRA adapter matrices are not trainable here. They can be applied, merged, saved and loaded, and a task head trains over a frozen encoder. Train the adapters themselves with PEFT in Python and serve them here.
- Sentence pairs are approximate. The segment-0 embedding is folded into the word embeddings exactly; segment 1 cannot be.
- Diffusion needs an ONNX export, not the PyTorch weights.
- Uploads are capped at 10 MB. Real weights need Git LFS, which GraviHub does not implement.
How it compares to Python
Measured against the reference implementation on the same machine in the same session — full method and caveats in docs/benchmarks.md.
| Python | HF.Net | ||
|---|---|---|---|
| Tokenize 1,000 documents | 18.1 ms | 10.9 ms | 1.66x faster |
| Open a 420 MB checkpoint, list 206 tensors | 0.65 ms | 0.71 ms | level |
| Read one 30,522 × 768 tensor | 1.1 ms | 197 ms | 173x slower |
| bert-base forward pass, 1 document | 50.8 ms | 300–600 ms | 6–12x slower |
| The same work through ONNX Runtime | — | 0.67 ms | the production path |
Tokenization is faster than the Rust tokenizers crate, and the ids are identical. Reading a
tensor is slower because every value is widened to double — structural, not fixable. Managed
inference is much slower than torch, and that is the expected shape: the managed encoder exists so
a model can be loaded, inspected and understood in pure .NET. When you need throughput, export
to ONNX and run it through GraviOptimum.
And they agree. Same prompt, same checkpoint, top five identical to a tenth of a percentage point:
The capital of France is [MASK].
python hf.net
1 paris 41.68% paris 41.53%
2 lille 7.14% lille 7.16%
3 lyon 6.34% lyon 6.31%
HFAppGen
tools/HFAppGen is an Avalonia IDE whose assistant — Jack, the Code Bender — builds HF.Net
applications from a prompt. It writes the files, runs the build, and fixes what the compiler says.
Supports OpenAI, Azure OpenAI, Claude, Gemini and Ollama through Semantic Kernel; everything is
configured in app.config and editable from the UI.
The banded rule under the toolbar is the offset rail: eight spans, one per HF.Net library, each as wide as that library's real share of the source.
dotnet run --project tools/HFAppGen
dotnet run --project tools/HFAppGen -- --selftest # one headless round trip
See docs/HFAppGen.md.
Repository layout
src/ one class library per Gravi* project
samples/ Gravi*.Console apps
tests/ Gravi*.Tests — 178 tests, no network required
benchmarks/ Gravi*.Benchmark (BenchmarkDotNet)
notebooks/ .NET Interactive notebooks
datasets/ titanic.csv, iris.csv, imdb_reviews.csv, finance_timeseries.csv
docs/ one page per library, plus id/ mirroring every page
tools/HFAppGen/ the Avalonia app generator
Commands
dotnet build HF.Net.sln -c Release
dotnet test # every test
dotnet test tests/GraviHub.Tests # one project
dotnet test tests/GraviHub.Tests --filter "FullyQualifiedName~SafeTensors"
dotnet run --project samples/GraviHub.Console
dotnet run -c Release --project benchmarks/GraviHub.Benchmark
dotnet format
Requirements
- .NET 10 SDK
- An internet connection for anything that touches the Hub (the built-in datasets and every test work offline)
Licence
MIT.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Gravicode.HFNet.GraviDatasets (>= 0.1.0)
- Gravicode.Science.GraviFrame (>= 1.0.0)
- Gravicode.Science.GraviLearn (>= 1.0.0)
- Gravicode.Science.GraviNum (>= 1.0.0)
- ILGPU (>= 1.5.3)
- ILGPU.Algorithms (>= 1.5.3)
- Parquet.Net (>= 5.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.