# Breaking the Silicon Barrier: Hacking AMD’s Instella-3B into llama.cpp for HFT

**URL:** <https://devcommunity.amd.com/t/breaking-the-silicon-barrier-hacking-amd-s-instella-3b-into-llama-cpp-for-hft/618>\
**Category:** AMD Ryzen AI\
**Tags:** ai, ryzen-ai, amd\
**Created:** [June 16, 2026, 10:12pm UTC](https://devcommunity.amd.com/t/breaking-the-silicon-barrier-hacking-amd-s-instella-3b-into-llama-cpp-for-hft/618 "2026-06-16T22:12:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wilderman\_Duarte](https://avatars.discourse-cdn.com/v4/letter/w/258eb7/32.png) [@Wilderman\_Duarte](https://devcommunity.amd.com/u/Wilderman_Duarte)\
**Post date:** [June 16, 2026, 10:12pm UTC](https://devcommunity.amd.com/t/breaking-the-silicon-barrier-hacking-amd-s-instella-3b-into-llama-cpp-for-hft/618/1 "2026-06-16T22:12:28Z")

</div>

1. The Context & The Bottleneck  
I was building an AI-driven High-Frequency Trading (HFT) bot (“WE Trading”) powered by the Instella-3B model. My initial setup used HuggingFace transformers and  
PyTorch running through a Python wrapper (llm\_engine.py), which was then bridged to my Node.js application.  
The result? Absolute disaster.  
Due to Python’s Global Interpreter Lock (GIL) and the massive overhead of mapping 16-bit precision tensors in VRAM, the AI was thinking in “slow motion.” It generated  
around 15 tokens per second. In the HFT world, this meant the bot was virtually blind. It would miss critical first-minute market operations simply because the AI was still  
computing its response. The latency alone guaranteed a loss before the trade even began.  
I needed the raw, bare-metal speed of C++. I needed llama.cpp with Vulkan acceleration.
2. The Architecture Wall (AMD’s Custom Tensors)  
I attempted a standard conversion using convert\_hf\_to\_gguf.py, but the compiler violently crashed:  
ValueError: Missing \<MODEL\_TENSOR.ATTN\_K\_NORM: 53\> for MODEL\_TENSORS of \<MODEL\_ARCH.LLAMA: 2\>  
Upon inspecting the safetensors, I discovered that AMD didn’t just use a vanilla LLaMA architecture. They injected custom normalization layers (q\_norm and k\_norm)  
into the attention blocks. The strict GGUF specification for LLAMA expects exactly 9 tensors per block (query, key, value, output, gate, up, down, input\_norm,  
post\_attention\_norm). Instella-3B had 11.  
The C++ engine panicked to prevent memory corruption and aborted the quantization.
3. The Hack: Tensor Spoofing & Architecture Forgery  
I couldn’t just delete q\_norm and k\_norm without destroying the model’s mathematics. Instead, I had to trick both the Python converter and the C++ engine into natively  
accepting these tensors.  
Here is exactly how I pulled it off for anyone trying to replicate this on forums:  
Step A: Mapping the Tensors to Olmo2  
I realized that the Olmo2ForCausalLM architecture natively expects q\_norm and k\_norm in the llama.cpp codebase. So, I wrote a Python script to physically modify the  
.safetensors on disk, translating the LLaMA layer names into the exact nomenclature expected by Olmo2.  
import torch  
from safetensors.torch import load\_file, save\_file  
import json  
model\_path = “model.safetensors”  
tensors = load\_file(model\_path)  
new\_tensors = {}  
for k, v in tensors.items():  
new\_k = k

# Spoofing the layernorms to match Olmo2 expectations

if “input\_layernorm” in new\_k:  
new\_k = new\_k.replace(“input\_layernorm”, “post\_attention\_layernorm”)  
elif “post\_attention\_layernorm” in new\_k and “input\_layernorm” not in k:  
new\_k = new\_k.replace(“post\_attention\_layernorm”, “post\_feedforward\_layernorm”)  
new\_tensors[new\_k] = v  
save\_file(new\_tensors, model\_path)

# Forcing the configuration header

with open(“config.json”, “r”) as f:  
c = json.load(f)  
c[“architectures”] = [“Olmo2ForCausalLM”]  
with open(“config.json”, “w”) as f:  
json.dump(c, f, indent=2)  
Step B: The 8-bit Quantization  
With the architecture successfully forged, convert\_hf\_to\_gguf.py parsed exactly 399 tensors flawlessly. I compiled it down to 8-bit precision (q8\_0), shrinking the 15GB  
monstrosity into a highly optimized 3.31 GB .gguf executable block.  
python convert\_hf\_to\_gguf.py “Instella-3B-Fused” --outfile “Instella-Trading-3B.gguf” --outtype q8\_0  
Step C: Native API Translation  
Finally, I destroyed the Python middleman. I booted llama-server.exe using Vulkan to offload all 36 layers directly to my AMD Radeon GPU.  
I patched my Node.js bot to shoot raw OpenAI-compatible REST payloads directly to the C++ server running on localhost:8000.  
const options = {  
hostname: ‘127.0.0.1’,  
port: 8000,  
path: ‘/v1/chat/completions’,  
method: ‘POST’,  
headers: { ‘Content-Type’: ‘application/json’ }  
};  
// Payload sent directly to C++ memory  
4. The Result: Institutional Speed  
The transformation is staggering. The bot’s AI no longer causes guaranteed first-minute losses. We pushed the inference speed from ~15 t/s to +100 tokens per second.  
The AI now maps the TradingView DOM, analyzes the order flow, and executes decisions in milliseconds. The bottleneck has been entirely eradicated. From this point  
forward, any losses incurred by the bot will be standard market risks (external actors, black swans, algorithmic collision) and absolutely not a failure of the AI’s reaction time.  
We brought institutional, bare-metal HFT capabilities to a consumer machine.

---

<div class="post-metadata">

**Author:** ![Hakob\_Arzumanyan](https://dub1.discourse-cdn.com/amd/user_avatar/devcommunity.amd.com/hakob_arzumanyan/32/214_2.png) [@Hakob\_Arzumanyan](https://devcommunity.amd.com/u/Hakob_Arzumanyan)\
**Post date:** [June 17, 2026, 10:13am UTC](https://devcommunity.amd.com/t/breaking-the-silicon-barrier-hacking-amd-s-instella-3b-into-llama-cpp-for-hft/618/2 "2026-06-17T10:13:03Z")

</div>

Hello, if you are serious about HFT and want to save every single millisecond, you should drop the local HTTP REST server. Instead, compile llama.cpp as a library and write a native Node.js addon (N-API) to run inference in-process, which will bypass all the JSON and HTTP socket overhead and save you another 2–3ms per trade. But this is a very clever piece of graph surgery as well. Thanks for sharing.

---

<div class="post-metadata">

**Author:** ![Wilderman\_Duarte](https://avatars.discourse-cdn.com/v4/letter/w/258eb7/32.png) [@Wilderman\_Duarte](https://devcommunity.amd.com/u/Wilderman_Duarte)\
**Post date:** [June 17, 2026, 12:42pm UTC](https://devcommunity.amd.com/t/breaking-the-silicon-barrier-hacking-amd-s-instella-3b-into-llama-cpp-for-hft/618/3 "2026-06-17T12:42:05Z")

</div>

Hello, I’m sharing that by doing what I posted, I managed to increase the speed from 42–45 tokens per second (t/s) to 180–190 t/s. It was a formidable change; in fact, I’m running everything in real-time. I make adjustments and continuously check what works and what doesn’t. I’ll keep your recommendation in mind and try it out in a few days. I’ll let you know if it works for me. Thank you!
