Overview
This report assesses the feasibility of hardware acceleration for Hugot, a Go-language library built on ONNX that lets developers run Hugging Face Transformer models (inference and fine-tuning) inside Go applications without any Python runtime or external services. Hugot is maintained by Knights Analytics and used in production for AI-driven data-cleaning pipelines. It supports pipelines including text classification, text generation, feature extraction (embeddings), image classification, object detection, question answering, zero-shot classification, cross-encoders, and named entity recognition.
Key points
- Three pluggable backends:
- Pure Go (SimpleGo) — default backend built on GoMLX; no C/C++ dependencies, small container images, works with CGO disabled. Optimized for smaller models with batch sizes around 32; larger workloads should use C-based backends.
- ONNX Runtime (ORT) — enabled with
-tags ORT; the fastest CPU inference backend and the only one supporting generative pipelines (text generation). Requireslibonnxruntime.so, configurable viaWithOnnxLibraryPath. Hardware acceleration is enabled through ORT execution providers (e.g.,WithCuda). - OpenXLA — enabled with
-tags XLA; the only backend supporting model training/fine-tuning and TPU acceleration (via GoMLX's PJRT plugin). Generative pipeline support is still incomplete. - Accelerator support:
- GPU (CUDA): mature and high-performance. Requires compatible NVIDIA drivers and CUDA/cuDNN versions (e.g., ONNX Runtime 1.24.4 needs CUDA 12.x, cuDNN 9.x). Benchmarks cited: an NVIDIA L4 GPU was ~12.6x faster than a 192-core AMD EPYC CPU on a satellite-image embedding model; ~11x faster even with CPU threads maxed out.
- TPU: available through the XLA backend with
WithTPU; best suited to Google Cloud deployments needing extreme throughput. Google reported first-gen TPU inference at 83x CPU performance and 29x GPU performance. - NPU: indirectly supported via ORT execution providers such as NNAPI (Android), CoreML (Apple Neural Engine), and OpenVINO (Intel VPUs); compatibility and gains vary by device and may require model pruning/quantization.
- Other: TensorRT EP (kernel fusion on NVIDIA GPUs), DirectML EP (Windows/DirectX 12), OpenVINO EP (Intel hardware).
- Performance tuning:
- Batch size strongly affects throughput; ~32 per batch is a good starting point for the pure Go backend.
- ORT thread options (
WithInterOpNumThreads,WithIntraOpNumThreads) and disabling the memory arena/pattern (WithCpuMemArena(false),WithMemPattern(false)) reduce contention in concurrent goroutine workloads. - GPU device selection via
WithCuda; multiple sessions can bind different GPUs for horizontal scaling. - ORT graph optimization via
WithGraphOptimizationLevel; quantization support (including 4-bit) is planned. - Deployment suitability:
- Cloud: containerized deployment with provided Dockerfile/compose files; no Python runtime needed, avoiding HTTP round-trips and serialization overhead compared to calling external Python inference services.
- Edge: feasible on higher-end edge devices with GPUs or NPUs through ORT execution providers; low-power devices depend on model size and NPU operator support. *(Source post truncated at this point.)*
- Ecosystem compatibility: models trained in Python can be exported to ONNX via
transformers.onnxor Optimum and are expected to produce identical predictions in Hugot, enabling loss-free migration from Python research to Go production environments.
Conclusion
Hardware acceleration in Hugot is technically feasible across CPU, GPU, TPU, and NPU targets. GPU acceleration via the ORT CUDA provider is the most mature and practical option for latency-sensitive, high-throughput production deployments; TPU suits Google Cloud workloads requiring maximum throughput; NPU support extends Hugot to edge and mobile scenarios, subject to per-device validation.