go-pherence

module
v0.0.0-...-99ac9cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT

README

go-pherence

go-pherence

go-pherence is a Go inference toolkit for running transformer, speech and experimental vision models on local hardware. The default paths are pure Go: CPU execution uses checked AVX2, NEON and RVV kernels with scalar fallbacks, while NVIDIA support loads PTX through the driver API without CGo or a CUDA toolkit.

The repository is deliberately broad -- it includes production-shaped LLM and speech paths alongside work-in-progress model families and embedded accelerator experiments -- so the documentation separates runnable features from engineering notes and historical snapshots.

Try it

Download a small MLX Qwen checkpoint:

mkdir -p checkpoints/qwen3-0.6b
for f in config.json model.safetensors tokenizer.json; do
  curl -L "https://huggingface.co/mlx-community/Qwen3-0.6B-4bit/resolve/main/$f" \
    -o "checkpoints/qwen3-0.6b/$f"
done

Run it on CPU or NVIDIA:

# AVX2/NEON with checked scalar fallbacks
go run ./cmd/llm/llmgen \
  -model checkpoints/qwen3-0.6b \
  -tokens 50 \
  -prompt "The meaning of life is"

# Runtime-loaded PTX; no CUDA toolkit required
go run ./cmd/llm/llmgen \
  -gpu \
  -model checkpoints/qwen3-0.6b \
  -tokens 50 \
  -prompt "The meaning of life is"

Interactive chat and the OpenAI-compatible server use the same model loader:

go run ./cmd/llm/llmchat -model checkpoints/qwen3-0.6b -gpu -n 256
go run ./cmd/llm/llmserver -model checkpoints/qwen3-0.6b -gpu -listen :8080

Speech

For library use, github.com/rcarmo/go-pherence/loader/audio/media exports media.NewGo264(media.Go264Config{}): a pure-Go media.Adapter for PCM WAV and the documented progressive AAC-LC MP4/M4A subset. It emits canonical 16 kHz mono S16 WAV and works with media.OpenCanonicalPCM, without FFmpeg, model weights, cgo or special build tags. See import example and format limits. The MIT provider github.com/rcarmo/go-264/audio can also be imported directly. Existing CLI and speech-job defaults still use FFmpeg; the pure-Go adapter is selected explicitly.

There are two native speech paths:

  • cmd/audio/diarize-vtt runs Whisper transcription or translation and can produce resumable WebVTT with optional speaker labels. It accepts ordinary media through ffmpeg.
  • cmd/audio/moss-transcribe runs the pinned MOSS-Transcribe-Diarize graph end to end, including recording-local speaker labels and timestamps. Its verified RTX 3060 path is 2.18x faster than the final forced-CPU path on the JFK fixture.
# Translate Spanish audio to English WebVTT
go run ./cmd/audio/diarize-vtt \
  -input meeting.m4a \
  -output meeting.vtt \
  -language es

# Native MOSS transcription and diarisation from 16kHz mono PCM WAV
make moss-transcribe
bin/moss-transcribe \
  -model-dir checkpoints/MOSS-Transcribe-Diarize \
  -audio meeting.wav \
  -format srt \
  -output meeting.srt

See Whisper and translated VTT and MOSS transcription and diarisation for model assets, limits and parity gates.

What runs today

The compact support matrix is in Supported models. In practical terms:

  • LLaMA, Qwen and Gemma-family decoders cover dense and MoE checkpoints in MLX, GPTQ, BF16/F16/F32 and selected GGUF layouts.
  • BERT/GTE encoders, Whisper and MOSS have native inference paths.
  • Jevlike provides tiny/frozen choice scoring, training, evaluation and reusable visual/action adapters. Game environments, recordings and demo orchestration are outside the port.
  • GLiNER 2.5 runs native entity, classification, relation, record and mixed-schema inference against the published checkpoint. Its guide distinguishes the supported API from broader upstream compatibility.
  • DiffusionGemma and Ideogram 4 have runnable native slices with explicit model-specific limits.
  • Qwen3-TTS, LFM2, Hunyuan3D, Trellis2 and Z-Image vary from metadata/processor support to partial runtime execution; their support pages state the exact boundary.

Backend selection is automatic where it is safe. -gpu selects NVIDIA for the general LLM commands; model-specific commands document their own switches and CPU override. See Backend selection and Tuning before changing cache, placement or worker settings.

Find the right document

The documentation index is organised by task rather than by implementation history. Useful starting points are:

Current guidance lives in topic folders under docs/; dated investigations and chronological logs are indexed in history. Provenance and package-specific validation remain beside their implementations.

Source and checkpoints

model/ contains all model implementation source, including BERT, Whisper, speaker and OmniVoice. checkpoints/ contains downloaded weights, configs and tokenizers and is entirely ignored by Git. cmd/models/ groups inspector tools; docs/models/ contains support guides.

The downloader defaults to checkpoints/; use CHECKPOINTS_DIR with Make or --checkpoints-dir with the Python helpers to select another location. See asset setup and migration for older checkouts and the change from models/<family> to model/<family> Go imports.

Build and test

make host-build
make host-vet
make host-test

# Compile Linux/RISC-V K3 code and test binaries without executing them
make spacemit-cross-compile

Host checks respect Go build constraints: Linux/RISC-V AICPU and TCM execution is not forced into amd64 or ARM64 tests, while portable packing and scalar fallbacks remain checked. Cross-build success is compilation evidence only. Validation gates lists hardware and asset requirements and the latest validation results; the host targets do not hide unrelated errors.

License

MIT

Directories

Path Synopsis
backends
ggmlexec
Package ggmlexec contains the GGML lowering planner for go-pherence graphs.
Package ggmlexec contains the GGML lowering planner for go-pherence graphs.
mlx
Package mlx contains backend-neutral helpers for MLX-style affine quantized weights.
Package mlx contains backend-neutral helpers for MLX-style affine quantized weights.
nvidia
Package nvidia is the namespace for NVIDIA backend implementations.
Package nvidia is the namespace for NVIDIA backend implementations.
nvidia/ptx
Code generated by scripts/generate-mojev-ptx.sh; CUDA 12.8, sm_86; DO NOT EDIT.
Code generated by scripts/generate-mojev-ptx.sh; CUDA 12.8, sm_86; DO NOT EDIT.
simd
Package simd is the namespace for CPU SIMD backend implementations.
Package simd is the namespace for CPU SIMD backend implementations.
simd/fft
Package fft provides FFT primitives for audio processing.
Package fft provides FFT primitives for audio processing.
simd/quant/fp8
Package fp8 implements weight-only float8 (E4M3FN) linear matrices as used by the Ideogram 4 FP8 DiT checkpoints.
Package fp8 implements weight-only float8 (E4M3FN) linear matrices as used by the Ideogram 4 FP8 DiT checkpoints.
spacemit/aicpu
Package aicpu is the Linux/RISC-V-only pure-Go transformer inference engine for the SpaceMIT K3 SoC (MilkV Jupiter 2).
Package aicpu is the Linux/RISC-V-only pure-Go transformer inference engine for the SpaceMIT K3 SoC (MilkV Jupiter 2).
spacemit/aicpu/aipool
Package aipool provides the aicpu worker pool: a TCM-aware, barrier-synchronized pool that fans quantized GEMM work (AIGemmSpec) across the K3's cores, with optional TCM B-wave activation staging.
Package aipool provides the aicpu worker pool: a TCM-aware, barrier-synchronized pool that fans quantized GEMM work (AIGemmSpec) across the K3's cores, with optional TCM B-wave activation staging.
spacemit/aicpu/config
Package config holds the aicpu feature flags, all driven by IME2_* environment variables.
Package config holds the aicpu feature flags, all driven by IME2_* environment variables.
spacemit/board
Package k3 provides a prioritised compute-backend stack for the SpacemiT K3 SoC (MilkV Jupiter 2 and similar boards).
Package k3 provides a prioritised compute-backend stack for the SpacemiT K3 SoC (MilkV Jupiter 2 and similar boards).
spacemit/ime2
Package ime2 implements low-level int8 matrix-multiply kernels for the SpaceMIT K3 IME (Integrated Matrix Engine), using the X60 RVV vmadot instructions, plus a generic barrier-based WorkerPool that fans GEMM work across cores.
Package ime2 implements low-level int8 matrix-multiply kernels for the SpaceMIT K3 IME (Integrated Matrix Engine), using the X60 RVV vmadot instructions, plus a generic barrier-based WorkerPool that fans GEMM work across cores.
spacemit/inference
Package inference provides mid-level numeric building blocks layered on top of the ime2 kernels: activation quantization, RMSNorm, and Q4_K / INT8 mat-vec routines (serial, parallel, and WorkerPool-backed).
Package inference provides mid-level numeric building blocks layered on top of the ime2 kernels: activation quantization, RMSNorm, and Q4_K / INT8 mat-vec routines (serial, parallel, and WorkerPool-backed).
spacemit/ort
Package spacemitort contains integration scaffolding for SpacemiT's ONNX Runtime Execution Provider on K-series RISC-V boards.
Package spacemitort contains integration scaffolding for SpacemiT's ONNX Runtime Execution Provider on K-series RISC-V boards.
spacemit/rvv
Package rvv implements low-level RISC-V Vector (RVV 1.0) SIMD kernels for the SpaceMIT K3 X60 cores: int8 GEMM (dot and register-blocked outer-product), W4A8, byte-copy, and q8 block quantization.
Package rvv implements low-level RISC-V Vector (RVV 1.0) SIMD kernels for the SpaceMIT K3 X60 cores: int8 GEMM (dot and register-blocked outer-product), W4A8, byte-copy, and q8 block quantization.
spacemit/tcm
Package tcm is a driver for the SpaceMIT K3 TCM (Tightly-Coupled Memory), the on-chip SRAM scratchpad.
Package tcm is a driver for the SpaceMIT K3 TCM (Tightly-Coupled Memory), the on-chip SRAM scratchpad.
training
Package training defines portable admission for GPU training primitives.
Package training defines portable admission for GPU training primitives.
cmd
audio/diarize-vtt command
Command diarize-vtt produces a diarized WebVTT transcript from an audio file.
Command diarize-vtt produces a diarized WebVTT transcript from an audio file.
audio/internal/whisperflags
Package whisperflags centralizes Whisper GPU CLI flag handling shared by the audio command binaries (whisper, diarize-vtt).
Package whisperflags centralizes Whisper GPU CLI flag handling shared by the audio command binaries (whisper, diarize-vtt).
audio/moss-transcribe command
Command moss-transcribe runs MOSS-Transcribe-Diarize entirely in native Go.
Command moss-transcribe runs MOSS-Transcribe-Diarize entirely in native Go.
audio/nemotron command
Command nemotron runs the bounded native Nemotron ASR or diarization stream.
Command nemotron runs the bounded native Nemotron ASR or diarization stream.
audio/omnivoice command
omnivoice is a native CPU development probe, not yet an end-to-end TTS CLI.
omnivoice is a native CPU development probe, not yet an end-to-end TTS CLI.
audio/pockettrain command
pockettrain provides Linux CPU preflight, recording preparation and explicitly experimental SIMD or attention-backward hybrid training.
pockettrain provides Linux CPU preflight, recording preparation and explicitly experimental SIMD or attention-backward hybrid training.
audio/pockettts command
audio/qwen3tts-twoframe command
qwen3tts-twoframe is a bounded 160 ms native CPU parity probe for the pinned Qwen3-TTS 0.6B CustomVoice checkpoint, not a general TTS CLI.
qwen3tts-twoframe is a bounded 160 ms native CPU parity probe for the pinned Qwen3-TTS 0.6B CustomVoice checkpoint, not a general TTS CLI.
audio/speakercheck command
Command speakercheck validates the speaker diarization path without running Whisper.
Command speakercheck validates the speaker diarization path without running Whisper.
audio/speechjob command
speechjob is an HTTP client, not an inference server or model runner.
speechjob is an HTTP client, not an inference server or model runner.
audio/transcribe-web command
Command transcribe-web exposes the durable speechjobserve queue through a trusted-LAN, no-login browser interface.
Command transcribe-web exposes the durable speechjobserve queue through a trusted-LAN, no-login browser interface.
audio/whisper command
Command whisper transcribes audio files using the Whisper speech recognition model.
Command whisper transcribes audio files using the Whisper speech recognition model.
gliner2 command
gliner2 runs native entity scoring and explicit basic span decoding.
gliner2 runs native entity scoring and explicit basic span decoding.
image/internal/k3flags
Package k3flags applies the shared Ideogram4 K3/RVV environment toggles for the image command-line tools.
Package k3flags applies the shared Ideogram4 K3/RVV environment toggles for the image command-line tools.
internal/dgflags
Package dgflags reads the shared DiffusionGemma runtime environment toggles used by the diffusiongemma command-line tools.
Package dgflags reads the shared DiffusionGemma runtime environment toggles used by the diffusiongemma command-line tools.
jevcompare command
jevlike command
llm/internal/promptfile
Package promptfile loads benchmark/eval prompts for the cmd/llm speculative decoding commands.
Package promptfile loads benchmark/eval prompts for the cmd/llm speculative decoding commands.
llm/llmchat command
llm/llmgen command
llm/llmserver command
llm/servebench command
llm/specbench command
llm/speccheck command
models/embcheck command
needle command
Command needle runs native Needle2/Needle3 token-ID reference inference/training.
Command needle runs native Needle2/Needle3 token-ID reference inference/training.
qwen/qwen36run command
spacemit/spacemit_bench command
cmd/spacemit_bench benchmarks all available compute backends on the K3 SoC.
cmd/spacemit_bench benchmarks all available compute backends on the K3 SoC.
spacemit/spacemit_run command
spacemit_run — run LLaMA inference from a GGUF file using the k3 multi-backend stack.
spacemit_run — run LLaMA inference from a GGUF file using the k3 multi-backend stack.
tinydemo command
Package half provides IEEE-754 half-precision (FP16) and bfloat16 (BF16) to float32 conversion.
Package half provides IEEE-754 half-precision (FP16) and bfloat16 (BF16) to float32 conversion.
internal
commandcapture
Package commandcapture runs owned helper commands with bounded captured output.
Package commandcapture runs owned helper commands with bounded captured output.
contextmutex
Package contextmutex provides a reusable context-aware mutex.
Package contextmutex provides a reusable context-aware mutex.
floatcmp
Package floatcmp provides small float-slice comparison helpers for tests.
Package floatcmp provides small float-slice comparison helpers for tests.
httpinput
Package httpinput provides bounded single-document HTTP JSON decoding.
Package httpinput provides bounded single-document HTTP JSON decoding.
loader
audio
Package audio provides audio I/O, resampling, and mel spectrogram computation for speech models (Whisper).
Package audio provides audio I/O, resampling, and mel spectrogram computation for speech models (Whisper).
audio/media
Package media probes local audio files and decodes them to a canonical speech WAV suitable for downstream loaders.
Package media probes local audio files and decodes them to a canonical speech WAV suitable for downstream loaders.
gguf
Package gguf implements a minimal GGUF v2/v3 reader that dequantizes tensor data to []float32.
Package gguf implements a minimal GGUF v2/v3 reader that dequantizes tensor data to []float32.
gguf/internal/q4layout
Package q4layout validates extents before the experimental C/Plan9 kernels.
Package q4layout validates extents before the experimental C/Plan9 kernels.
omnivoice
Package omnivoice loads OmniVoice configuration metadata and validates safetensors checkpoint headers against the expected OmniVoice/Qwen3 tensor layout.
Package omnivoice loads OmniVoice configuration metadata and validates safetensors checkpoint headers against the expected OmniVoice/Qwen3 tensor layout.
silero
Package silero reads the pinned legacy GGML Silero 16-kHz VAD format.
Package silero reads the pinned legacy GGML Silero 16-kHz VAD format.
whisperggml
Package whisperggml reads legacy whisper.cpp GGML model storage.
Package whisperggml reads legacy whisper.cpp GGML model storage.
GGUFLlama is a pure-Go LLaMA forward pass loaded from a GGUF file.
GGUFLlama is a pure-Go LLaMA forward pass loaded from a GGUF file.
decider
Package decider implements Mapika Decider's typed one-pass decision contract.
Package decider implements Mapika Decider's typed one-pass decision contract.
gemma4
Package model contains Gemma4 diagnostic tests.
Package model contains Gemma4 diagnostic tests.
gliner2
Package gliner2 parses the published GLiNER2.5 boundary checkpoint metadata.
Package gliner2 parses the published GLiNER2.5 boundary checkpoint metadata.
gosystemone
Package gosystemone implements finite-schema decisions over Gemma4 token logits.
Package gosystemone implements finite-schema decisions over Gemma4 token logits.
hunyuan3d
Package hunyuan3d contains metadata and validation helpers for Tencent Hunyuan3D shape-generation checkpoints.
Package hunyuan3d contains metadata and validation helpers for Tencent Hunyuan3D shape-generation checkpoints.
ideogram4
Package ideogram4 contains native metadata and runtime scaffolding for Ideogram 4 text-to-image checkpoints.
Package ideogram4 contains native metadata and runtime scaffolding for Ideogram 4 text-to-image checkpoints.
inspect
Package inspect provides small, type-independent predicates shared by the model-family tensor-readiness/fixture inspection layers (e.g.
Package inspect provides small, type-independent predicates shared by the model-family tensor-readiness/fixture inspection layers (e.g.
jevlike
Package jevlike provides validated JSONL loading, byte-level batching and small dataset builders for JEV-like multiple-choice tasks.
Package jevlike provides validated JSONL loading, byte-level batching and small dataset builders for JEV-like multiple-choice tasks.
lfm2
Package lfm2 contains metadata and validation helpers for Liquid AI LFM2 checkpoints.
Package lfm2 contains metadata and validation helpers for Liquid AI LFM2 checkpoints.
mosstranscribe
Package mosstranscribe implements the native MOSS-Transcribe-Diarize model.
Package mosstranscribe implements the native MOSS-Transcribe-Diarize model.
needle
Package needle implements the distinct Needle 2 and Needle 3 architectures.
Package needle implements the distinct Needle 2 and Needle 3 architectures.
nemotronasr
Package nemotronasr contains bounded native operators for the pinned Nemotron 3.5 ASR checkpoint.
Package nemotronasr contains bounded native operators for the pinned Nemotron 3.5 ASR checkpoint.
nemotrondiarization
Package nemotrondiarization contains bounded native operators for the pinned NVIDIA Nemotron 3 Diarization checkpoint.
Package nemotrondiarization contains bounded native operators for the pinned NVIDIA Nemotron 3 Diarization checkpoint.
omnivoice
Package omnivoice implements the native CPU numerical core of OmniVoice.
Package omnivoice implements the native CPU numerical core of OmniVoice.
openjev
Package openjev implements the native text NLI contract of AlexWortega/openjev.
Package openjev implements the native text NLI contract of AlexWortega/openjev.
pockettts
Package pockettts implements Kyutai Pocket TTS in native Go/SIMD.
Package pockettts implements Kyutai Pocket TTS in native Go/SIMD.
qwen3tts
Package qwen3tts contains metadata, token constants, and validation helpers for Qwen3-TTS checkpoints.
Package qwen3tts contains metadata, token constants, and validation helpers for Qwen3-TTS checkpoints.
qwenimage21
Package qwenimage21 provides native Qwen Image 2.1 model contracts and reusable CPU/SIMD primitives.
Package qwenimage21 provides native Qwen Image 2.1 model contracts and reusable CPU/SIMD primitives.
silero
Package silero implements native CPU inference for the pinned 16-kHz Silero 6.2.0 VAD graph.
Package silero implements native CPU inference for the pinned 16-kHz Silero 6.2.0 VAD graph.
simplejev
Package simplejev holds independently authored, model-free label scoring primitives for a future Simple-JEV-style adapter.
Package simplejev holds independently authored, model-free label scoring primitives for a future Simple-JEV-style adapter.
speaker
Package speaker implements speaker embedding and diarization models.
Package speaker implements speaker embedding and diarization models.
whisper
Package whisper implements OpenAI Whisper speech recognition models.
Package whisper implements OpenAI Whisper speech recognition models.
zimage
Package zimage implements weight-free reference slices for Z-Image-Turbo.
Package zimage implements weight-free reference slices for Z-Image-Turbo.
runtime
graph
Package graph defines a backend-neutral planned execution IR for model inference.
Package graph defines a backend-neutral planned execution IR for model inference.
kv
resourcebudget
Package resourcebudget provides cooperative, process-local CPU-slot and estimated-memory reservations.
Package resourcebudget provides cooperative, process-local CPU-slot and estimated-memory reservations.
sampling
Package sampling implements bounded top-k / top-p / temperature sampling over autoregressive next-token logits.
Package sampling implements bounded top-k / top-p / temperature sampling over autoregressive next-token logits.
speechjob
Package speechjob provides an opt-in durable store for sequential speech jobs.
Package speechjob provides an opt-in durable store for sequential speech jobs.
speechjob/httpapi
Package httpapi exposes an opt-in, single-tenant HTTP boundary for speechjob.
Package httpapi exposes an opt-in, single-tenant HTTP boundary for speechjob.
scripts
decisioncompare command
decisioncompare records precision trade-offs for the pinned Gemma model.
decisioncompare records precision trade-offs for the pinned Gemma model.
qwen3tts-admission command
Run from the repository root with the approved, pinned CustomVoice checkpoint: GOMAXPROCS=2 GO_PHERENCE_DISABLE_NVIDIA=1 go run ./scripts/qwen3tts-admission <checkpoint-dir> Append --mixed to test Hi/seed-42 against Hello world/seed-7 at 16 frames.
Run from the repository root with the approved, pinned CustomVoice checkpoint: GOMAXPROCS=2 GO_PHERENCE_DISABLE_NVIDIA=1 go run ./scripts/qwen3tts-admission <checkpoint-dir> Append --mixed to test Hi/seed-42 against Hello world/seed-7 at 16 frames.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL