Text Generation
Transformers
Safetensors
Chinese
qwen3_5_text
qwen3_5
merged
psychological-counseling
counselor-response-generation
conversational
Run this model with HF Jobs
Run UEC-InabaLab/CounselTrajLM on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/UEC-InabaLab/CounselTrajLM. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/UEC-InabaLab/CounselTrajLM on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/UEC-InabaLab/CounselTrajLM. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/UEC-InabaLab/CounselTrajLM. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use UEC-InabaLab/CounselTrajLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UEC-InabaLab/CounselTrajLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="UEC-InabaLab/CounselTrajLM") 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") model = AutoModelForCausalLM.from_pretrained("UEC-InabaLab/CounselTrajLM", 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 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "UEC-InabaLab/CounselTrajLM" # 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", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/UEC-InabaLab/CounselTrajLM
- SGLang
How to use UEC-InabaLab/CounselTrajLM 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" \ --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", "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" \ --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", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use UEC-InabaLab/CounselTrajLM with Docker Model Runner:
docker model run hf.co/UEC-InabaLab/CounselTrajLM
Download generate_reply.py from UEC-InabaLab/CounselTrajLM: direct link, hf CLI and curl.
- Browser
- Download file 4.7 kB
-
https://huggingface.co/UEC-InabaLab/CounselTrajLM/resolve/341e9b198c985ee75c982a43376015d806b15522/generate_reply.py
- Command line
-
hf download hf://UEC-InabaLab/CounselTrajLM@341e9b198c985ee75c982a43376015d806b15522/generate_reply.py
-
curl -L -o generate_reply.py https://huggingface.co/UEC-InabaLab/CounselTrajLM/resolve/341e9b198c985ee75c982a43376015d806b15522/generate_reply.py
4.7 kB
| """Generate the next Chinese counselor reply with the CounselTrajLM adapter.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from peft import PeftModel | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig | |
| REPO_ID = "UEC-InabaLab/CounselTrajLM" | |
| BASE_MODEL = "Qwen/Qwen3.5-9B" | |
| BASE_REVISION = "c202236235762e1c871ad0ccb60c8ee5ba337b9a" | |
| SYSTEM_PROMPT = ( | |
| "你是一名专业、温和、自然的线上心理咨询师。" | |
| "请根据对话历史生成下一句咨询师回复。" | |
| "回复只写咨询师要说的话,不要写说话人名称,不要写对话标签。" | |
| ) | |
| def build_prompt(tokenizer, history): | |
| messages = [ | |
| {"role": "system", "content": SYSTEM_PROMPT}, | |
| { | |
| "role": "user", | |
| "content": f"对话历史:\n{history[-1800:]}\n\n请生成下一句咨询师回复。", | |
| }, | |
| ] | |
| return tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| enable_thinking=False, | |
| ) | |
| def load_model(adapter, base_model=BASE_MODEL, local_files_only=False, use_4bit=True): | |
| tokenizer = AutoTokenizer.from_pretrained(adapter, local_files_only=local_files_only) | |
| if tokenizer.pad_token_id is None: | |
| tokenizer.pad_token = tokenizer.eos_token | |
| kwargs = { | |
| "dtype": torch.bfloat16, | |
| "device_map": "auto", | |
| "attn_implementation": "eager", | |
| "local_files_only": local_files_only, | |
| } | |
| if base_model == BASE_MODEL: | |
| kwargs["revision"] = BASE_REVISION | |
| if use_4bit: | |
| kwargs["quantization_config"] = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_use_double_quant=True, | |
| bnb_4bit_quant_type="nf4", | |
| bnb_4bit_compute_dtype=torch.bfloat16, | |
| ) | |
| base = AutoModelForCausalLM.from_pretrained(base_model, **kwargs) | |
| model = PeftModel.from_pretrained(base, adapter, local_files_only=local_files_only) | |
| model.eval() | |
| return tokenizer, model | |
| def generate_reply(tokenizer, model, history, max_new_tokens=256): | |
| prompt = build_prompt(tokenizer, history) | |
| inputs = tokenizer( | |
| prompt, | |
| return_tensors="pt", | |
| add_special_tokens=False, | |
| truncation=True, | |
| max_length=2048, | |
| ).to(model.device) | |
| with torch.inference_mode(): | |
| output = model.generate( | |
| **inputs, | |
| max_new_tokens=max_new_tokens, | |
| do_sample=False, | |
| repetition_penalty=1.05, | |
| pad_token_id=tokenizer.pad_token_id, | |
| eos_token_id=tokenizer.eos_token_id, | |
| ) | |
| return tokenizer.decode( | |
| output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True | |
| ).strip() | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--adapter", default=REPO_ID) | |
| parser.add_argument("--base-model", default=BASE_MODEL) | |
| parser.add_argument("--history") | |
| parser.add_argument("--input-file", type=Path) | |
| parser.add_argument("--output-file", type=Path) | |
| parser.add_argument("--max-new-tokens", type=int, default=256) | |
| parser.add_argument("--local-files-only", action="store_true") | |
| parser.add_argument("--no-4bit", action="store_true") | |
| args = parser.parse_args() | |
| if bool(args.history) == bool(args.input_file): | |
| parser.error("Provide exactly one of --history or --input-file") | |
| rows = [{"id": "example", "history": args.history}] if args.history else [ | |
| json.loads(line) | |
| for line in args.input_file.read_text(encoding="utf-8").splitlines() | |
| if line.strip() | |
| ] | |
| if not rows or any(not isinstance(row.get("history"), str) or not row["history"].strip() for row in rows): | |
| parser.error("Every input row must contain a nonempty history string") | |
| tokenizer, model = load_model( | |
| args.adapter, | |
| base_model=args.base_model, | |
| local_files_only=args.local_files_only, | |
| use_4bit=not args.no_4bit, | |
| ) | |
| results = [] | |
| for row in rows: | |
| reply = generate_reply(tokenizer, model, row["history"], args.max_new_tokens) | |
| if not reply: | |
| raise RuntimeError("Empty reply for input " + str(row.get("id", ""))) | |
| result = {"id": row.get("id", ""), "history": row["history"], "response": reply} | |
| results.append(result) | |
| print(json.dumps(result, ensure_ascii=False), flush=True) | |
| if args.output_file: | |
| args.output_file.parent.mkdir(parents=True, exist_ok=True) | |
| args.output_file.write_text( | |
| "".join(json.dumps(row, ensure_ascii=False) + "\n" for row in results), | |
| encoding="utf-8", | |
| ) | |
| if __name__ == "__main__": | |
| main() | |