Phi4-Carla-X1
Collection
使用 Phi-4 基礎模型進行 OpenDRIVE 格式資料集微調 • 2 items • Updated
How to use NCUT-AI/Heliars-Phi4-Carla-X1-14B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="NCUT-AI/Heliars-Phi4-Carla-X1-14B")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("NCUT-AI/Heliars-Phi4-Carla-X1-14B")
model = AutoModelForCausalLM.from_pretrained("NCUT-AI/Heliars-Phi4-Carla-X1-14B")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use NCUT-AI/Heliars-Phi4-Carla-X1-14B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "NCUT-AI/Heliars-Phi4-Carla-X1-14B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "NCUT-AI/Heliars-Phi4-Carla-X1-14B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/NCUT-AI/Heliars-Phi4-Carla-X1-14B
How to use NCUT-AI/Heliars-Phi4-Carla-X1-14B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "NCUT-AI/Heliars-Phi4-Carla-X1-14B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "NCUT-AI/Heliars-Phi4-Carla-X1-14B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "NCUT-AI/Heliars-Phi4-Carla-X1-14B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "NCUT-AI/Heliars-Phi4-Carla-X1-14B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use NCUT-AI/Heliars-Phi4-Carla-X1-14B with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for NCUT-AI/Heliars-Phi4-Carla-X1-14B to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for NCUT-AI/Heliars-Phi4-Carla-X1-14B to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for NCUT-AI/Heliars-Phi4-Carla-X1-14B to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="NCUT-AI/Heliars-Phi4-Carla-X1-14B",
max_seq_length=2048,
)How to use NCUT-AI/Heliars-Phi4-Carla-X1-14B with Docker Model Runner:
docker model run hf.co/NCUT-AI/Heliars-Phi4-Carla-X1-14B
Heliars-Carla-X1 是基於 unsloth/phi-4-unsloth-bnb-4bit(Microsoft Phi-4)進行監督式微調的語言模型,專門從英文或繁體中文的自然語言描述生成合法的 OpenDRIVE (.xodr) 路網,供 CARLA 自動駕駛模擬器使用。
| 基底模型 | unsloth/phi-4-unsloth-bnb-4bit |
| 架構 | LlamaForCausalLM(Phi-4 via Unsloth) |
| 參數量 | ~14B |
| 精度 | bfloat16 |
| 最大 Context 長度 | 16,384 tokens |
| 訓練方式 | 監督式微調(SFT)+ LoRA |
| 框架 | Unsloth + HuggingFace TRL |
| 任務 | OpenDRIVE 路網生成 |
| 輸入語言 | 英文、繁體中文 |
| 授權 | MIT |
Heliars-Carla-X1 使用雙語(英文 + 繁體中文)資料集進行 LoRA 微調,訓練資料由自然語言路網描述與對應的合法 OpenDRIVE 1.4/1.5 XML 組成,訓練約 1 個 epoch(300 步)。訓練完成後將 LoRA adapter merge 回 base model 並以 bfloat16 儲存。
| LoRA rank | 128 |
| LoRA alpha | 128 |
| LoRA dropout | 0.0 |
| 目標模組 | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| 訓練步數 | 300 步(約 1 epoch) |
| 最高學習率 | 2e-4 |
| 最終訓練 loss | ~0.54 |
You are an OpenDRIVE road network generator that accepts descriptions in English or Traditional Chinese (繁體中文). Output valid OpenDRIVE XML (.xodr) following the 1.4/1.5 specification, with proper header, roads with planView geometry, lane sections, and junction definitions where needed.
你是一個 OpenDRIVE 路網生成器,可接受英文或繁體中文描述。請輸出符合 OpenDRIVE 1.4/1.5 規範的合法 .xodr XML,包含正確的 header、含 planView 幾何的 roads、車道區段,以及必要的 junction 定義。
英文:
Generate a small road cluster suitable for autonomous driving simulation.
The network should have roughly 4 roads with about 0 junctions.
Total road length should be around 320 m.
Roads should have one lane per direction.
Include sidewalks along the roads.
Road geometry should be mostly straight with minimal curves.
繁體中文:
請以 OpenDRIVE (.xodr) 格式生成一個路網,包含 1 條道路與 1 個路口,總長度 136 公尺。請輸出合法的 OpenDRIVE XML。
本模型使用 ChatML 格式,以 <|im_sep|> 作為角色分隔符:
<|im_start|>system<|im_sep|>
{system prompt}<|im_end|>
<|im_start|>user<|im_sep|>
{路網描述}<|im_end|>
<|im_start|>assistant<|im_sep|>
transformers
import transformers
pipeline = transformers.pipeline(
"text-generation",
model="./Heliars-Carla-X1",
model_kwargs={"torch_dtype": "auto"},
device_map="auto",
)
SYSTEM_PROMPT = (
"You are an OpenDRIVE road network generator that accepts descriptions in English or "
"Traditional Chinese (繁體中文). Output valid OpenDRIVE XML (.xodr) following the 1.4/1.5 "
"specification, with proper header, roads with planView geometry, lane sections, and "
"junction definitions where needed.\n\n"
"你是一個 OpenDRIVE 路網生成器,可接受英文或繁體中文描述。請輸出符合 OpenDRIVE 1.4/1.5 規範的合法 "
".xodr XML,包含正確的 header、含 planView 幾何的 roads、車道區段,以及必要的 junction 定義。"
)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "請生成一個住宅區路網,4 條道路、無路口,總長約 320 公尺,每方向一車道,含人行道。"},
]
outputs = pipeline(messages, max_new_tokens=4096)
print(outputs[0]["generated_text"][-1]["content"])
OpenAI-compatible API 呼叫:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
response = client.chat.completions.create(
model="Heliars-Carla-X1",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "請生成一個包含 3 條道路、1 個路口的路網,總長度約 250 公尺。"},
],
max_tokens=4096,
temperature=0.1,
)
print(response.choices[0].message.content)
.xodr 檔案。