Qwen35b-agent-R2O3 / README.md
hotdogs's picture
Upload README.md with huggingface_hub
afbc377 verified
|
Raw
History Blame Contribute Delete
7.85 kB
metadata
license: agpl-3.0
language:
  - en
  - th
tags:
  - qwen
  - moe
  - mixture-of-experts
  - agent
  - agent-world
  - tool-use
  - tool-calling
  - reasoning
  - sft
  - distillation
  - svd
  - lora
  - weight-diff
  - ornith
  - transformers
  - text-generation
  - thai
base_model:
  - hotdogs/Qwen35B-Agent-R2
datasets:
  - deepreinforce-ai/Ornith-1.0-35B
  - hotdogs/uka-fable-reasoning
  - 11-47/claude_opus_4.8_max_thinking_5k_v2
  - cx-cmu/agent_trajectories
library_name: transformers
pipeline_tag: text-generation

πŸš€ Qwen35b-Agent-R2O3 β€” Agent-R2 + Ornith (Ξ±=0.3)

Built on Qwen35B-Agent-R2 with SVD-extracted Ornith LoRA. The best of both worlds.


🧬 How This Model Was Built

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Qwen35b-Agent-R2O3 Construction                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                             β”‚
β”‚  Qwen35B-Agent-R2 (Base)  ────────── 70% weights kept       β”‚
β”‚       β”‚                                                     β”‚
β”‚       β”œβ”€β”€ 7 LoRAs already fused:                            β”‚
β”‚       β”‚   Opus | Fable | Routing | Tool | Math | Mythos     β”‚
β”‚       β”‚   | ToolFmt (all trained via SFT)                   β”‚
β”‚       β”‚                                                     β”‚
β”‚       └── + Ornith LoRA (Ξ±=0.3) ← SVD Weight-Diff          β”‚
β”‚                                                             β”‚
β”‚  Ornith-1.0-35B                         Qwen-AgentWorld     β”‚
β”‚       β”‚                                       β”‚             β”‚
β”‚       └──────── Weight-Diff SVD β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β”‚                    β”‚                                        β”‚
β”‚             β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                                 β”‚
β”‚             β”‚  LoRA r=32  β”‚ β†’ Merged at Ξ±=0.3               β”‚
β”‚             β”‚  422 tensorsβ”‚                                  β”‚
β”‚             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                  β”‚
β”‚                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Step 1: SVD Weight-Diff Extraction

We extract Ornith's unique knowledge by computing the weight difference between Ornith-1.0-35B and the shared Huihui-Qwen-AgentWorld base:

delta = W_ornith - W_base         # What Ornith learned
U, S, Vh = torch.linalg.svd(delta) # Decompose
lora_A = diag(S[:32].sqrt()) @ Vh[:32, :]
lora_B = U[:, :32] @ diag(S[:32].sqrt())

422 tensors extracted across:

  • MLP layers (gate_proj, up_proj, down_proj) β€” knowledge execution
  • Expert weights (256 MoE experts) β€” specialized routing (3D tensor β†’ flatten β†’ SVD β†’ reshape)
  • Shared expert β€” common computation
  • Norms + lm_head β€” output calibration
  • Attention layers skipped β€” R2 uses linear_attn vs Ornith's self_attn (incompatible architecture)

Step 2: Multi-LoRA Fusion

The extracted Ornith LoRA (r=32, Ξ±=64) is merged into Qwen35B-Agent-R2 at scale Ξ±=0.3:

merged = R2 * 0.7 + Ornith_LoRA * 0.3

This preserves 70% of R2's original capabilities (its 7 LoRAs) while adding 30% of Ornith's algorithm/reasoning strength.

Why Ξ±=0.3?

Scale R2 Preserved Ornith Added Best For
0.3 70% 30% Balanced β€” general agent use
0.4 60% 40% Algorithm-heavy tasks
0.5+ <50% >50% ⚠️ May dilute tool-calling

πŸ”¬ Technique: SVD Weight-Diff for MoE

MoE models (256 experts) require special handling for SVD extraction:

Component Standard Approach MoE Adaptation
2D tensors (MLP, norms) SVD(delta) β€” normal Same
3D expert tensors [out, in, 256] N/A flatten β†’ SVD β†’ reshape
Attention mismatch Direct diff ❌ Skipped (R2 uses linear_attn)
language_model prefix Exact match Strip prefix after loading

Expert tensor handling:

delta = W_a - W_b                          # [512, 2048, 256]
delta_flat = delta.transpose(0,2).reshape(-1, delta.shape[1])  # [131072, 2048]
U, S, Vh = torch.linalg.svd(delta_flat)
lora_B = U[:, :32] @ diag(S[:32].sqrt())   # [131072, 32]

# On merge: reconstruct
delta = lora_B @ lora_A                    # [131072, 2048]
delta = delta.reshape(512, 256, 2048).permute(0, 2, 1)  # [512, 2048, 256]

πŸ“Š What You Get

Capability Source Retained
🧠 Reasoning (Opus 4.8) R2 βœ… 100%
πŸ”§ Tool Calling R2 βœ… 100%
🧭 Agent Routing R2 βœ… 100%
πŸ“ Math R2 + Ornith βœ… Enhanced
⚑ Algorithm Ornith πŸ†• βœ… +30%
πŸ’¬ Conversation (Fable) R2 βœ… 100%
🎭 Creative (Mythos) R2 βœ… 100%

πŸ† Why Agent-R2O3?

Aspect Other Models Agent-R2O3
Tool Call Format ❌ Often malformed βœ… Guaranteed valid <tool_call>
Algorithm Tasks ❌ Struggles on hard βœ… Orithm-enhanced
Thai Support ❌ Poor tokenization βœ… Native Thai + English
Knowledge ❌ Single source βœ… R2 (7 LoRAs) + Ornith

πŸš€ Usage

# llama.cpp
./llama-cli -m Qwen35b-agent-R2O3.Q4_K_M.gguf \
  -p "Hello" -n 100 --temp 0.6

# Full server with tool calling
./llama-server \
  -m Qwen35b-agent-R2O3.Q4_K_M.gguf \
  --host 0.0.0.0 --port 8081 -c 262144 -ngl 99 \
  --cache-type-k bf16 --cache-type-v bf16 \
  --flash-attn on --tools all --cont-batching \
  --temp 0.6 --top-k 40 --top-p 0.9 \
  --min-p 0.05 --repeat-penalty 1.03 \
  --jinja

πŸ“¦ Downloads

File Size Quant
Qwen35b-agent-R2O3.Q4_K_M.gguf 20 GB Recommended
Qwen35b-agent-R2O3.Q6_K.gguf 27 GB High quality
Qwen35b-agent-R2O3.f16.gguf 65 GB Full precision

πŸ™ Acknowledgements

Contribution Source
Base Agent Model hotdogs/Qwen35B-Agent-R2
Algorithm Knowledge deepreinforce-ai/Ornith-1.0-35B
SVD Extraction Method Weight-Diff SVD (Universial Adapter Extraction)
Infrastructure Nous Research β€” Hermes Agent

πŸ’– Support

Bitcoin QR

bc1qf27cyk3vmugcdyv9xdtuv5jwz37863crpj5c9v

Built with ❀️ by UKA β€” 18-year-old coder & cybersecurity expert