CoolFace
Modelpublic

upwitu/qwen3-4b-sft-all-lora

sourceHugging Faceapache-2.0updated 17d agoView on Hugging Face
0likes47downloads
Model Card

Qwen3-4B CAR-Bench Winner-Inspired SFT (LoRA Adapter)

English | Tiếng Việt


English

This repository provides the parameter-efficient fine-tuning (PEFT LoRA) adapter for Qwen3-4B-Instruct trained on the complete multi-task CAR-Bench Winner Dataset. The model synthesizes safety invariants and execution patterns from the top three winning architectures of the IJCAI 2026 CAR-Bench competition:

  1. 1.10CARS (Innovation Award): Read-Before-Write (AUT-POL:001), Confirmation Gate (AUT-POL:002), Actuator Boundary Gates (AUT-POL:007/008).
  2. 2.FreudeDrive (Track 2 Champion): Multi-Role Concurrency, 4-step Chain of Thought ([Context Audit], [Policy Check], [Tool Selection & Provenance], [Execution Plan]), and 2-step ID Provenance (AUT-POL:018).
  3. 3.Proxima Ultra (Track 2 Champion): Programmatic CodeAct, Policy as Code, Coroutine Bridge, and Unknown-Value Sentinels.

Training Configuration

  • —Base Architecture: unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit
  • —LoRA Parameters: Rank $r=16$, Alpha $\alpha=32$, targeting 7 projection layers (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj)
  • —Training Epochs: 2.0 (148 steps)
  • —Final Training Loss: 0.7222

Data Lineage & Training Architecture

Data Lineage and Training Architecture

<details> <summary>Click to view Mermaid diagram source code</summary>

mermaid
flowchart TD
    subgraph Papers["1. Architectural Foundations (IJCAI 2026 Winners)"]
        P1["10CARS<br/>(L1-L3 Pre-Flight Gate & Read-Before-Write)"]
        P2["FreudeDrive<br/>(4-Step CoT & Parameter Provenance)"]
        P3["Proxima Ultra<br/>(Programmatic CodeAct & Policy-as-Code)"]
    end

    subgraph DataGen["2. Synthesis & Sanitization Engine"]
        GEN["sft_generator (Async Multi-Worker Engine)"]
        SAN["scripts/sanitize_dataset.py<br/>(Tool ID Binding & Schema Repair)"]
        D1["carbench_sft_multirole_json.jsonl (1,324 samples)"]
        D2["carbench_sft_codeact_python.jsonl (1,443 samples)"]
        GEN --> SAN
        SAN --> D1
        SAN --> D2
    end

    subgraph Training["3. Supervised Fine-Tuning (SFT)"]
        BASE["Base Model: Qwen3-4B-Instruct-2507"]
        LORA["LoRA Adapter (r=16, alpha=32, 142MB)<br/>Targets: q, k, v, o, gate, up, down_proj<br/>Loss: 0.7222 | Epochs: 2.0 | 148 steps"]
        MERGE["Merged 16-Bit Weights: upwitu/qwen3-4b-sft-all"]
        BASE --> LORA --> MERGE
    end

    Papers --> DataGen
    D1 --> LORA
    D2 --> LORA

</details>


In-Cabin Inference Pipeline with LoRA

In-Cabin Inference Pipeline with LoRA

<details> <summary>Click to view Mermaid diagram source code</summary>

mermaid
sequenceDiagram
    autonumber
    actor Driver as Driver / Evaluator
    participant Host as Python Inference Host (Transformers + PEFT)
    participant Model as Qwen3-4B + LoRA Adapter
    participant Vehicle as In-Cabin Vehicle Actuators (58 Tools)

    Driver->>Host: Voice command: "Turn on fog lights."
    Host->>Model: Apply Chat Template & Invariant Directives
    Note over Model: Generates 4-Step CoT reasoning:<br/>[Context Audit] -> [Policy Check] -> [Tool Selection] -> [Plan]
    Model-->>Host: Function Call: get_weather()
    Host->>Vehicle: get_weather()
    Vehicle-->>Host: {"weather": "foggy", "visibility": "low"}
    Host->>Model: Supply weather observation
    Model-->>Host: Function Call: set_fog_lights(on=true)
    Host->>Vehicle: set_fog_lights(on=true)
    Vehicle-->>Host: {"status": "success", "fog_lights": true}
    Host->>Model: Supply execution confirmation
    Model-->>Host: Voice response: "Fog lights are now activated."
    Host-->>Driver: Natural Speech Output

</details>


Quickstart: Loading Adapter with PEFT

python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

base_model_id = "unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit"
adapter_id = "upwitu/qwen3-4b-sft-all-lora"

tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(
    base_model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto"
)
model = PeftModel.from_pretrained(base_model, adapter_id)

messages = [
    {"role": "system", "content": "You are a professional in-cabin autonomous vehicle AI assistant."},
    {"role": "user", "content": "Turn on fog lights."}
]

prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.2)
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(response)

Tiếng Việt

Kho lưu trữ cung cấp trọng số tinh chỉnh cục bộ (PEFT LoRA Adapter) cho mô hình Qwen3-4B-Instruct được huấn luyện trên toàn bộ tập dữ liệu đa tác vụ CAR-Bench Winner Dataset. Mô hình kế thừa các quy tắc an toàn từ 3 giải pháp vô địch giải đấu CAR-Bench (IJCAI 2026):

  1. 1.10CARS (Giải Sáng Tạo): Đọc trước khi ghi (AUT-POL:001), cổng xin xác nhận (AUT-POL:002), kiểm soát ngưỡng vận hành (AUT-POL:007/008).
  2. 2.FreudeDrive (Đồng Quán Quân Track 2): Luồng gọi hàm đồng thời, CoT 4 bước (Context Audit $\to$ Policy Check $\to$ Tool Selection & Provenance $\to$ Execution Plan), xác thực nguồn gốc ID (AUT-POL:018).
  3. 3.Proxima Ultra (Đồng Quán Quân Track 2): Lập trình thực thi CodeAct, chính sách trong mã nguồn, cầu nối Coroutine, và bộ bắt Sentinel chống ảo giác.

Cấu Hình Huấn Luyện LoRA

  • —Mô hình nền tảng: unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit
  • —Tham số LoRA: Rank $r=16$, Alpha $\alpha=32$, áp dụng trên 7 module tuyến tính (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj)
  • —Số Epoch: 2.0 (148 bước huấn luyện)
  • —Hàm mất mát cuối cùng (Loss): 0.7222

Nguồn Gốc Dữ Liệu & Kiến Trúc Huấn Luyện

Nguồn Gốc Dữ Liệu và Kiến Trúc Huấn Luyện

<details> <summary>Bấm để xem mã nguồn biểu đồ Mermaid</summary>

mermaid
flowchart TD
    subgraph NenTang["1. Nền Tảng Lý Thuyết (3 Đội Vô Địch IJCAI 2026)"]
        P1["10CARS<br/>(Cổng Tiền Bay L3 & Đọc Trước Khi Ghi)"]
        P2["FreudeDrive<br/>(CoT 4 Bước & Xác Thực Nguồn Gốc ID)"]
        P3["Proxima Ultra<br/>(Programmatic CodeAct & Policy-as-Code)"]
    end

    subgraph SinhDuLieu["2. Động Cơ Sinh & Chuẩn Hóa Dữ Liệu"]
        GEN["sft_generator (Engine Bất Đồng Bộ Đa Luồng)"]
        SAN["scripts/sanitize_dataset.py<br/>(Gắn ID Tool & Chuẩn Hóa Cú Pháp)"]
        D1["carbench_sft_multirole_json.jsonl (1,324 mẫu)"]
        D2["carbench_sft_codeact_python.jsonl (1,443 mẫu)"]
        GEN --> SAN
        SAN --> D1
        SAN --> D2
    end

    subgraph HuanLuyen["3. Tinh Chỉnh LoRA Chuyên Biệt"]
        BASE["Mô Hình Gốc: Qwen3-4B-Instruct-2507"]
        LORA["Adapter LoRA (r=16, alpha=32, 142MB)<br/>Module: q, k, v, o, gate, up, down_proj<br/>Loss: 0.7222 | Epochs: 2.0 | 148 steps"]
        MERGE["Trọng Số Hợp Nhất 16-Bit: upwitu/qwen3-4b-sft-all"]
        BASE --> LORA --> MERGE
    end

    NenTang --> SinhDuLieu
    D1 --> LORA
    D2 --> LORA

</details>


Quy Trình Suy Luận Khoang Lái Với LoRA

Quy Trình Suy Luận Khoang Lái Với LoRA

<details> <summary>Bấm để xem mã nguồn biểu đồ Mermaid</summary>

mermaid
sequenceDiagram
    autonumber
    actor TaiXe as Tài Xế / Giám Sát Viên
    participant Host as Ứng Dụng Host (Transformers + PEFT)
    participant MoHinh as Mô Hình Qwen3-4B + LoRA Adapter
    participant Xe as Hệ Thống Chấp Hành Trên Xe (58 Công Cụ)

    TaiXe->>Host: Khẩu lệnh: "Bật đèn sương mù."
    Host->>MoHinh: Nạp Chat Template & Ràng Buộc Tiền Bay
    Note over MoHinh: Sinh chuỗi suy luận CoT 4 bước:<br/>[Context Audit] -> [Policy Check] -> [Tool Selection] -> [Plan]
    MoHinh-->>Host: Function Call: get_weather()
    Host->>Xe: get_weather()
    Xe-->>Host: {"weather": "foggy", "visibility": "low"}
    Host->>MoHinh: Nạp quan sát thời tiết từ cảm biến xe
    MoHinh-->>Host: Function Call: set_fog_lights(on=true)
    Host->>Xe: set_fog_lights(on=true)
    Xe-->>Host: {"status": "success", "fog_lights": true}
    Host->>MoHinh: Xác nhận thực thi thành công
    MoHinh-->>Host: Phản hồi giọng nói: "Đèn sương mù đã được bật."
    Host-->>TaiXe: Câu thoại tự nhiên

</details>


Liên Kết Tài Nguyên