Architecture
~9 min readUpdated: November 2026

Tencent Hy4-Flash Agent Architecture: Benchmarks & Serving

Tencent Hy4-Flash Agent Architecture — 220B LatentMoE, Hybrid Attention, Engram N-Gram Embeddings, and DFly2 Speculative Decoding

Tencent Hy4-Flash establishes an open multimodal Mixture-of-Experts architecture: 220B total parameters activating 11.3B text parameters per token across a 1,048,576 token context window. Featuring LatentMoE routing across 512 experts, 63.5B Engram n-gram hash lookup tables, hybrid sparse and sliding-window attention, and a built-in 0.85B DFly2 speculative decoding drafter, Hy4-Flash matches Claude Haiku 5.5 in blind developer evaluations while slashing task execution costs to one-twentieth of dense frontier models. Smoke Monkey Harness and Canvas orchestrate Hy4-Flash across Model Context Protocol (MCP) toolchains with zero telemetry leakage.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

Tencent Hy4-Flash Agent Architecture: Benchmarks & Serving: Tencent Hy4-Flash establishes an open multimodal Mixture-of-Experts architecture: 220B total parameters activating 11.3B text parameters per token across a 1,048,576 token context window. Featuring LatentMoE routing across 512 experts, 63.5B Engram n-gram hash lookup tables, hybrid sparse and sliding-window attention, and a built-in 0.85B DFly2 speculative decoding drafter, Hy4-Flash matches Claude Haiku 5.5 in blind developer evaluations while slashing task execution costs to one-twentieth of dense frontier models. Smoke Monkey Harness and Canvas orchestrate Hy4-Flash across Model Context Protocol (MCP) toolchains with zero telemetry leakage. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Exampletencent-hy4-flash-agent.ts
tencent-hy4-flash-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Initialize sovereign autonomous engineering agent powered by Tencent Hy4-Flash
const agent = createAgent({
agentId: 'hy4-systems-engineer',
provider: 'custom',
baseUrl: 'http://localhost:8000/v1',
model: 'tencent/Hy4-flash-FP8',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'allow',
run_command: 'ask',
},
sampling: {
temperature: 0.9,
top_p: 1.0,
max_tokens: 32768,
extra_body: {
chat_template_kwargs: {
reasoning_effort: 'high',
},
},
},
tools: [
{
name: 'ast_code_analyzer',
description: 'Parses multi-file AST trees to extract type definitions and dependency graphs',
parameters: {
type: 'object',
properties: {
targetFiles: { type: 'array', items: { type: 'string' }, description: 'Repository files to inspect' },
symbolQuery: { type: 'string', description: 'Exported symbol or interface identifier' },
},
required: ['targetFiles', 'symbolQuery'],
},
handler: async ({ targetFiles, symbolQuery }) => {
return { matchedSymbols: [symbolQuery], referencesFound: 14, scope: 'workspace' };
},
},
{
name: 'execute_cargo_verify',
description: 'Executes compiler checks and integration tests for low-level system modules',
parameters: {
type: 'object',
properties: {
testFilter: { type: 'string', description: 'Cargo test filter string' },
},
required: ['testFilter'],
},
handler: async ({ testFilter }) => {
return { exitCode: 0, status: 'pass', output: 'test result: ok. 32 passed; 0 failed;' };
},
},
],
});
// Execute autonomous verification and refactoring loop
const execution = await agent.run(
'Inspect memory pooling layer, vectorize SIMD buffer operations, and verify compilation'
);
console.log('Execution Completed:', execution.summary);
Video Guides

Watch: Related Video Guides

Tencent Hunyuan Hy4: MoE Architecture & Computer Use

Tencent Hunyuan Large MoE AI Model - Architecture & Hands-on Testing

Tencent Hy4-Flash Architecture: 220B LatentMoE & Engram Grounding

Tencent Hy4-Flash is an open-weight 220-billion parameter multimodal Mixture-of-Experts (MoE) foundation model that activates 11.3 billion text parameters per token across 42 layers. It replaces standard routing with a 1,536-dimensional LatentMoE space and integrates 63.5 billion hash-addressed Engram n-gram parameters across four residual streams with Identity Hyper-Connections (iHC).

Language Backbone & LatentMoE Formulation

The language backbone contains 42 layers structured as 1 initial dense feed-forward layer followed by 41 MoE layers. In conventional MoE networks, tokens are routed to experts in full hidden-dimension space, which introduces severe memory bandwidth bottlenecks when scaling expert counts. Tencent Hy4-Flash resolves this with LatentMoE: routed experts operate in a compressed 1,536-dimensional latent space.

Each MoE layer incorporates 512 routed experts alongside 1 dedicated shared expert. For each token, the gating mechanism dynamically routes across 16 active experts. This architecture retains high representational capacity while bounding parameter activation to 11.3B text parameters per token (11.73B total active parameters including the vision encoder).

Identity Hyper-Connections (iHC)

To stabilize gradient propagation through 41 MoE routing layers, Hy4-Flash implements identity Hyper-Connections (iHC) across 4 residual streams. Rather than relying on a single additive skip connection, iHC distributes activations across multiple parallel residual channels, preventing representational collapse during long-horizon agent trajectories.

Engram N-Gram Embedding Integration

Hy4-Flash augments traditional token embeddings with 63.5B parameters of explicit bigram and trigram representations, termed Engram. Injected at backbone layers 1, 11, 21, and 31, Engram uses 8 hash heads per n-gram order to query a 10.3M entry hash vocabulary table. Each head contributes 96 dimensions, forming a 768-dimensional embedding per order. This direct lexical lookup anchors code syntax and token combinations without requiring intermediate transformer layer capacity.

Adapted SigLIP2 Vision Encoder

Multimodal processing is handled by a 27-layer vision encoder adapted from SigLIP2-So400m-Patch16-Res512 (0.43B parameters, hidden size 1,152, 16 attention heads). Visual tokens are merged 2×2 and projected through an MLP into the language backbone, enabling sovereign agent visual grounding for GUI navigation, UI mockups, and architectural diagrams.

Active vs Static Memory Profile

Although Hy4-Flash houses 220B total parameters across its backbone and Engram tables, only 11.73B parameters are activated during any single forward pass, delivering 12B-class inference latency.

Hybrid Attention & KV Cache Compression: Scaling to 1,048,576 Tokens

Tencent Hy4-Flash handles 1,048,576 context tokens by interleaving 12 sparse IndexPool attention layers with 30 sliding-window attention (SWA) layers at a 1:3 ratio. Using Multi-head Latent Attention (MLA) with decoupled RoPE and 2,048-token group selection, it compresses KV cache memory footprint to 1/24 of Hy3 and 1/6 of Hy4.

Interleaved Layer Distribution Pattern

Standard dense attention scales quadratic attention matrix calculations and linearly inflates KV cache size as context expands to 1M tokens. Hy4-Flash eliminates this bottleneck by interleaving sparse and local attention mechanisms in a deterministic 42-layer sequence:

$$\text{Pattern} = 2 \times \text{Sparse} \longrightarrow 10 \times (3 \times \text{SWA} \longrightarrow \text{Sparse})$$

  • Sparse Attention (12 Layers): Features 32 attention heads with a RoPE base of 10,000,000. Employs group-level IndexPool selection to dynamically attend to at most 2,048 relevant context tokens from the entire 1M history.
  • Sliding-Window Attention (30 Layers): Features 64 attention heads with a RoPE base of 10,000, maintaining a strict 512-token causal window (511 historical tokens + current token).

Multi-Head Latent Attention (MLA) Dynamics

Hy4-Flash uses Multi-Head Latent Attention (MLA) across all 42 layers, applying low-rank projection to query, key, and value vectors:

  • Query LoRA Rank ($q_{\text{lora}}$): 1,024
  • KV LoRA Rank ($kv_{\text{lora}}$): 512
  • QK Head Dimension: 192 non-RoPE dimensions + 64 RoPE dimensions (256 total)
  • Value Head Dimension: 256

KV Cache Memory Footprint Comparison Table

Model Architecture128K Context KV Cache512K Context KV Cache1,048,576 Context KV CacheCompression Factor
Dense Attention (Hy3)64.0 GB256.0 GB512.0 GB1.0x (Baseline)
Hybrid Attention (Hy4)16.0 GB64.0 GB128.0 GB4.0x reduction
Tencent Hy4-Flash (MLA + SWA)2.67 GB10.67 GB21.33 GB24.0x reduction

At maximum 1,048,576 token context, the entire KV cache consumes just 21.33 GB of VRAM, enabling complete million-token repository analysis on dual NVIDIA RTX 4090 or single A100/H100 instances.

Decoupled RoPE Base Mapping

Sparse layers operate with a RoPE base of 10,000,000 to preserve long-range positional fidelity, while SWA layers operate with RoPE base 10,000 to maximize local syntactic resolution.

DFly2 Speculative Decoding: Achieving >150 Tokens/Second Throughput

DFly2 is a built-in 5-layer, 0.85-billion parameter speculative decoding drafter embedded within Tencent Hy4-Flash that reuses the target model's KV cache and sparse indices. By sharing the 2,048 selected token positions with zero duplicate KV allocations, DFly2 sustains generation throughput exceeding 150 tokens per second across long developer contexts.

The Mechanics of Top-k Sparse KV Reuse

Conventional speculative decoding pairs an independent small drafter model with a large target model. However, running a standalone drafter across 1M context windows requires replicating the multi-gigabyte KV cache, exhausting memory bandwidth. DFly2 resolves this by directly mounting onto Hy4-Flash through two mechanisms:

  1. KV Share: Each of DFly2's 5 draft layers reads directly from the target model's sparse attention KV cache tensors. Zero secondary KV memory is allocated for the drafter.
  2. Index Share: DFly2 inherits the compressed IndexPool token selection (up to 2,048 positions) already computed by the target model, bypassing redundant context scoring.

Prefill-Decode (PD) Disaggregation

During prompt prefill, DFly2 is completely dormant, introducing zero compute overhead. When decoding commences, the prefill-to-decode transfer passes only a single last-layer hidden state vector. Because each speculative draft step attends to at most ~2,000 keys, draft generation runs in bounded constant time ($O(1)$ with respect to total context length).

Speculative Throughput Comparison

text
Standard Autoregressive Decoding:  [Token 1] -> [Token 2] -> [Token 3] -> [Token 4]  (~38 tok/s)

DFly2 Speculative Block (5 Tokens): [Draft 1-5 in Parallel] ===> [Single Target Verify Step] (>150 tok/s)

Benchmarked on 8x NVIDIA H800 clusters in FP8 precision, DFly2 achieves an average acceptance rate of 78.4% across code generation tasks, accelerating end-to-end task completion by 3.4x.

AngelSpec Verification Framework

DFly2 was trained with Tencent AngelSpec, optimizing speculative drafting loss specifically against the top-k sparse indices of the 220B target backbone.

Empirical Benchmark Verification: WorkIndex, Code, and Hardware Sizing

Tencent Hy4-Flash scores 42.1 on Tencent's internal WorkIndex benchmark, outperforming Hy4 preview (39.7) at one-thirteenth the operational cost. In blind user evaluations with 85 software engineers across 259 tasks, Hy4-Flash scored 2.79/4 satisfaction—matching Claude Haiku 5.5 (2.81/4)—while delivering the fastest median completion turnaround of 6.7 minutes at RMB 0.26 per task.

Frontier Benchmark Evaluation

Benchmark Evaluation SuiteEvaluation SettingHy4-Flash BaseHy4 BaseDeepSeek-V4.1-FlashClaude Haiku 5.5
WorkIndex (Agent Tasks)8 Task Clusters42.151.441.842.4
MMLU (Knowledge)5-shot88.7%91.6%89.7%89.2%
ARC-Challenge (Reasoning)0-shot95.0%97.3%97.3%94.8%
C-Eval (Chinese STEM)5-shot92.0%95.0%91.9%88.4%
CMMLU (Advanced QA)5-shot91.6%93.1%89.8%87.9%
MMMU-Pro (Multimodal)4-shot, 10 opts52.0%59.6%—51.2%
RealWorldQA (Vision)4-shot71.1%72.3%—70.8%
Belebele (Multilingual)5-shot93.8%95.0%94.4%93.5%
Median Task Turnaround259 Blind Tasks6.7 min14.2 min8.9 min7.4 min
Relative Task CostUSD Normalized1.0x20.0x8.0x14.5x

Hardware Sizing & Memory Footprint Calculations

Deployment ConfigurationPrecision FormatStatic Weights VRAM128K KV CacheMinimum Hardware TopologyThroughput (DFly2)
FP8 Tensor Parallel 8FP8 MoE + FP8 SWA238 GB2.67 GB8x RTX 4090 (24GB) or 4x A100 (80GB)>150 tokens/sec
AngelSlim INT4 / FP4INT4 MoE + FP8 Attn124 GB2.67 GB2x A100 (80GB) or 4x RTX 6000 Ada~115 tokens/sec
AngelSlim GGUF Q4_K_M4-bit Quantized118 GB2.67 GBApple M2/M3/M4 Ultra (128GB Unified)~26 tokens/sec
BF16 Full Weights16-bit Float476 GB5.34 GB8x H100 (80GB SXM5)~90 tokens/sec

Cost Efficiency Multiplier

Hy4-Flash delivers 92% of frontier model coding capabilities at 1/20th the operational cost of dense architectures, making continuous automated regression loops economically viable.

Production Deployment Guide: Docker, vLLM, and SGLang Serving

Production serving of Tencent Hy4-Flash requires either vLLM with FlashMLA sparse kernels or SGLang with native DFLY speculative decoding algorithms. Both runtimes expose OpenAI-compatible REST endpoints that integrate directly into Smoke Monkey Harness to drive autonomous tool-calling loops with zero data exfiltration.

Production Serving with vLLM Docker

Launch the official vllm/vllm-openai:hy4-flash container with tensor parallelism across 8 GPUs, enabling sparse attention kernels and native tool parsing:

bash
docker run --gpus all \
  -p 8000:8000 \
  --ipc=host \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  vllm/vllm-openai:hy4-flash tencent/Hy4-flash-FP8 \
    --tensor-parallel-size 8 \
    --speculative-config '{"num_speculative_tokens":5,"method":"dfly"}' \
    --attention-backend FLASHMLA_SPARSE \
    --tool-call-parser hy_v4 \
    --reasoning-parser hy_v4 \
    --enable-auto-tool-choice \
    --port 8000 \
    --served-model-name hy4-flash

Production Serving with SGLang Docker

Alternatively, launch lmsysorg/sglang:hy4-flash configured with the native DFLY speculative algorithm and a 6-token block size:

bash
docker run --gpus all \
  -p 8000:8000 \
  --ipc=host \
  lmsysorg/sglang:hy4-flash \
  sglang serve \
    --trust-remote-code \
    --model-path tencent/Hy4-flash-FP8 \
    --tp 8 \
    --cuda-graph-backend-prefill disabled \
    --speculative-algorithm DFLY \
    --speculative-dfly-block-size 6 \
    --host 0.0.0.0 \
    --port 8000

Verification via OpenAI-Compatible API Request

bash
curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "hy4-flash",
    "messages": [
      {"role": "user", "content": "Analyze memory alignment constraints in this SIMD ring buffer."}
    ],
    "temperature": 0.9,
    "top_p": 1.0,
    "extra_body": {"chat_template_kwargs": {"reasoning_effort": "high"}}
  }'

Reasoning Mode Selection

Pass reasoning_effort: 'high' for complex multi-file architectural refactoring, or reasoning_effort: 'no_think' for sub-second tool execution and conversational chat.

Google Search Questions & Answers

Frequently Asked Questions

Q:How does Tencent Hy4-Flash compress KV cache to 1/24 of previous generation architectures?

Hy4-Flash compresses KV cache to 1/24 of Hy3 by interleaving 12 sparse IndexPool attention layers with 30 sliding-window attention (SWA) layers at a 1:3 ratio. SWA layers restrict cache to a 512-token causal window, while sparse layers dynamically select up to 2,048 tokens via Multi-Head Latent Attention (MLA), keeping total 1M-context KV cache at just 21.33 GB.

Q:What makes the Engram N-gram embedding layer unique in Hy4-Flash compared to standard dense embeddings?

Engram introduces 63.5B parameters of bigram and trigram representations across layers 1, 11, 21, and 31. By querying an 8-head hash table with 10.3M vocabulary entries, the model retrieves 768-dimensional n-gram representations directly via deterministic hash lookups, grounding syntax and phrase semantics without consuming transformer attention capacity.

Q:How does DFly2 speculative decoding achieve zero auxiliary KV memory overhead?

DFly2 achieves zero auxiliary KV memory overhead through KV Share and Index Share: its 5 draft layers directly read the key-value tensors and index selections already computed by the target model's sparse attention layers. It attends to at most 2,048 keys in constant time, accelerating generation beyond 150 tokens/sec.

Q:What are the exact VRAM and hardware requirements to deploy Tencent Hy4-Flash locally?

In native FP8 precision, Hy4-Flash requires approximately 238 GB of VRAM, running on an 8x RTX 4090 (24GB) or 4x A100 (80GB) cluster. Under AngelSlim INT4 quantization, static weight footprint drops to 124 GB, fitting on dual A100s. Apple Silicon Macs with M2/M3/M4 Ultra chips and 128 GB of unified memory can run the model via AngelSlim GGUF Q4_K_M at ~26 tokens/sec.

Q:How does Smoke Monkey Harness integrate Tencent Hy4-Flash with Model Context Protocol (MCP) tools?

Smoke Monkey Harness connects to Hy4-Flash via vLLM or SGLang using the hy_v4 tool-call parser. The harness serializes MCP schemas into structured JSON function signatures, monitors the model's reasoning tokens, validates tool parameters locally, and executes system commands with strict human-in-the-loop permission sandboxing.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness