Inference

From VectorSpaceLab/AREX-Skill · View interactive version

Inference is an AI agent skill from the GitHub repository VectorSpaceLab/AREX-Skill. Operate Baichuan2 chat/base inference, terminal chat, Streamlit chat, and OpenAI-compatible chat-completions workflows.

How to use this skill

Skill file

Baichuan2 inference

Use this sub-skill when the user wants to run or understand Baichuan2 inference: Python chat snippets, Base-model text generation, the interactive terminal demo, the Streamlit chat UI, or the OpenAI-compatible /v1/chat/completions server.

Do not route quantization, CPU deployment conversion, model checkpoint normalization, fine-tuning, DeepSpeed training, or LoRA work here. Send those requests to the deployment or fine-tuning sub-skill.

Route by user intent

| User asks for | Route | Key files |

| --- | --- | --- |

| "chat with Baichuan2 in Python" or "use model.chat" | Chat Python recipe | CODE0 |

| "run the Base model" or "plain text completion" | Base-model generation recipe | CODE0 |

| "interactive CLI" or "terminal demo" | Chat CLI helper | CODE0 |

| "web demo" or "browser UI" | Streamlit helper | CODE0 |

| "OpenAI API compatible server" or "chat completions endpoint" | Flask API helper | CODE0, CODE1 |

| Load/model/runtime failure | Troubleshooting | CODE0 |

Core operating facts

Minimal chat model recipe

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig

model_id = "baichuan-inc/Baichuan2-13B-Chat"
tokenizer = AutoTokenizer.from_pretrained(
    model_id,
    use_fast=False,
    trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
)
model.generation_config = GenerationConfig.from_pretrained(model_id)

messages = [{"role": "user", "content": "解释一下“温故而知新”"}]
response = model.chat(tokenizer, messages)
print(response)

For streaming chat, call model.chat(tokenizer, messages, stream=True). The iterator yields progressively longer response strings, so terminal UIs should print only the delta after the previous position.

Bundled helpers

Run --help before loading weights:

python scripts/chat_cli.py --help
python scripts/run_openai_api.py --help
python scripts/chat_web_demo.py --help

Check launch configuration without downloading/loading weights:

python scripts/chat_cli.py --dry-run --model baichuan-inc/Baichuan2-13B-Chat
python scripts/run_openai_api.py --dry-run --host 127.0.0.1 --port 8000
python scripts/chat_web_demo.py --dry-run --model baichuan-inc/Baichuan2-13B-Chat

Launch examples:

# Terminal chat, Chat model only.
python scripts/chat_cli.py --model baichuan-inc/Baichuan2-13B-Chat --dtype float16 --stream

# OpenAI-compatible non-streaming API.
python scripts/run_openai_api.py --model baichuan-inc/Baichuan2-13B-Chat --host 0.0.0.0 --port 8000 --dtype float16

# Streamlit web UI. Streamlit server flags configure the web host/port;
# arguments after `--` are passed to the Baichuan2 helper.
streamlit run scripts/chat_web_demo.py --server.address 0.0.0.0 --server.port 8501 -- --model baichuan-inc/Baichuan2-13B-Chat --dtype float16

API behavior to remember

When to escalate

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.