Menu

Cutting LLM Fine-Tuning Memory in Pure Kotlin: Fused Linear Cross-Entropy and the JVM Vector API
📰

Cutting LLM Fine-Tuning Memory in Pure Kotlin: Fused Linear Cross-Entropy and the JVM Vector API

DEV Community: machinelearning·Angel Arellano·12 days ago
#YiHXyoZD
Long article (2361 words) — no AI summary yet.
Reading 0:00
15s threshold

When fine-tuning language models like Qwen2-0.5B or Llama-3 on a constrained heap, the biggest memory and compute bottleneck often isn't self-attention. On models with a small hidden dimension and a large vocabulary, the bottleneck is the output projection head ( lmHead ) and cross-entropy loss.

I ran into this while working on v1.1.0 of Kotensor ( io.github.tspstudio:kotensor ), an open-source, pure-Kotlin Transformer and reverse-mode autograd engine for JVM 17+ and Android with no native C++ or JNI dependencies. Inference was already reasonably fast and ran within tight mobile memory limits, but running a LoRA fine-tuning step on the full 24-layer Qwen2-0.5B architecture inside a 6 GB JVM heap consistently failed with OutOfMemoryError: Java heap space .

At first I looked for a reference leak in the autograd graph, assuming intermediate activations weren't being freed between steps.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.