Text Generation
Transformers
Safetensors
Chinese
qwen2
counseltraj
counseltrajlm
counseling
conversational
merged
text-generation-inference
Instructions to use UEC-InabaLab/CounselTrajLM-Qwen2.5-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UEC-InabaLab/CounselTrajLM-Qwen2.5-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="UEC-InabaLab/CounselTrajLM-Qwen2.5-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("UEC-InabaLab/CounselTrajLM-Qwen2.5-7B") model = AutoModelForCausalLM.from_pretrained("UEC-InabaLab/CounselTrajLM-Qwen2.5-7B", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use UEC-InabaLab/CounselTrajLM-Qwen2.5-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "UEC-InabaLab/CounselTrajLM-Qwen2.5-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UEC-InabaLab/CounselTrajLM-Qwen2.5-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/UEC-InabaLab/CounselTrajLM-Qwen2.5-7B
- SGLang
How to use UEC-InabaLab/CounselTrajLM-Qwen2.5-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "UEC-InabaLab/CounselTrajLM-Qwen2.5-7B" \ --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": "UEC-InabaLab/CounselTrajLM-Qwen2.5-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "UEC-InabaLab/CounselTrajLM-Qwen2.5-7B" \ --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": "UEC-InabaLab/CounselTrajLM-Qwen2.5-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use UEC-InabaLab/CounselTrajLM-Qwen2.5-7B with Docker Model Runner:
docker model run hf.co/UEC-InabaLab/CounselTrajLM-Qwen2.5-7B
Download generate_reply.py from UEC-InabaLab/CounselTrajLM-Qwen2.5-7B: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/UEC-InabaLab/CounselTrajLM-Qwen2.5-7B/resolve/main/generate_reply.py
- Command line
-
hf download hf://UEC-InabaLab/CounselTrajLM-Qwen2.5-7B/generate_reply.py
-
curl -L -o generate_reply.py https://huggingface.co/UEC-InabaLab/CounselTrajLM-Qwen2.5-7B/resolve/main/generate_reply.py
3.02 kB
| """Generate the next counselor response with the merged CounselTrajLM model.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| SYSTEM_PROMPT = ( | |
| "你是一名专业、温和、自然的线上心理咨询师。" | |
| "请根据对话历史生成下一句咨询师回复。" | |
| "回复只写咨询师要说的话,不要写说话人名称,不要写对话标签。" | |
| ) | |
| def load_messages(path): | |
| messages = json.loads(Path(path).read_text(encoding="utf-8")) | |
| if not isinstance(messages, list) or not messages: | |
| raise ValueError("Provide a non-empty JSON list of chat messages.") | |
| for i, message in enumerate(messages): | |
| if not isinstance(message, dict): | |
| raise ValueError("Each message must be a JSON object.") | |
| if message.get("role") not in {"system", "user", "assistant"}: | |
| raise ValueError("Message roles must be system, user, or assistant.") | |
| if message["role"] == "system" and i != 0: | |
| raise ValueError("A system message may appear only at the beginning.") | |
| if not isinstance(message.get("content"), str) or not message["content"].strip(): | |
| raise ValueError("Each message must have non-empty text content.") | |
| if messages[-1]["role"] != "user": | |
| raise ValueError("The dialogue must end with a client (user) message.") | |
| if messages[0]["role"] != "system": | |
| messages.insert(0, {"role": "system", "content": SYSTEM_PROMPT}) | |
| return messages | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--model", default="UEC-InabaLab/CounselTrajLM-Qwen2.5-7B") | |
| parser.add_argument("--messages", type=Path, default=Path(__file__).parent / "examples/history.json") | |
| parser.add_argument("--max-new-tokens", type=int, default=160) | |
| parser.add_argument("--greedy", action="store_true") | |
| args = parser.parse_args() | |
| messages = load_messages(args.messages) | |
| tokenizer = AutoTokenizer.from_pretrained(args.model) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| args.model, dtype=torch.bfloat16, device_map="auto" | |
| ).eval() | |
| prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| if inputs.input_ids.shape[-1] + args.max_new_tokens > model.config.max_position_embeddings: | |
| raise ValueError("The input plus requested output exceeds the model context window.") | |
| generation = { | |
| "max_new_tokens": args.max_new_tokens, | |
| "do_sample": not args.greedy, | |
| "repetition_penalty": 1.05, | |
| } | |
| if not args.greedy: | |
| generation.update(temperature=0.7, top_p=0.8, top_k=20) | |
| with torch.inference_mode(): | |
| outputs = model.generate(**inputs, **generation) | |
| reply = tokenizer.decode(outputs[0, inputs.input_ids.shape[-1]:], skip_special_tokens=True) | |
| print(reply.strip()) | |
| if __name__ == "__main__": | |
| main() | |