Text Generation
Transformers
Safetensors
English
Chinese
qwen2
llama-factory
full
Generated from Trainer
conversational
text-generation-inference
Instructions to use CogBase-USTC/SocraticLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CogBase-USTC/SocraticLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="CogBase-USTC/SocraticLM") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("CogBase-USTC/SocraticLM") model = AutoModelForCausalLM.from_pretrained("CogBase-USTC/SocraticLM") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use CogBase-USTC/SocraticLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CogBase-USTC/SocraticLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CogBase-USTC/SocraticLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/CogBase-USTC/SocraticLM
- SGLang
How to use CogBase-USTC/SocraticLM 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 "CogBase-USTC/SocraticLM" \ --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": "CogBase-USTC/SocraticLM", "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 "CogBase-USTC/SocraticLM" \ --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": "CogBase-USTC/SocraticLM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use CogBase-USTC/SocraticLM with Docker Model Runner:
docker model run hf.co/CogBase-USTC/SocraticLM
Model description
This model is a fine-tuned version of Qwen2.5-Math-7B-Instruct on the SocraTeach dataset.
It is an implementation of SocraticLM.
Intended uses & limitations
SocraticLM is designed for educational perposes, where students need a Socratic-style guidance when having difficulties learning to solve mathematical problems. Also, SocraticLM can solve mathematical problems itself.
This model mainly supports English and Chinese.
How to use
For Huggingface transformers:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("CogBase-USTC/SocraticLM")
model = AutoModelForCausalLM.from_pretrained(
"CogBase-USTC/SocraticLM",
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True
)
### Math Problem Solving ###
messages = [
{"role": "system", "content" : "Please analyse and solve the following problem step by step."},
{"role": "user", "content": "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?"},
]
### Socratic-style Guidance ###
# messages = [
# {"role": "system", "content" : "You are a Socratic teacher, please guide me to solve the [Problem] with heuristic questions based on the following information. \n"},
# {"role": "user", "content": "[Problem] Debelyn, Christel, and Andrena collect dolls. Debelyn had 20 dolls before she gave Andrena 2 dolls. Christel had 24 dolls before giving Andrena 5 dolls. After all the gifts, Andrena now has 2 more dolls than Christel, how many more dolls does andrena have now than Debelyn? [Answer] 3 [Analysis] Debelyn had 20 - 2 = 18 dolls left after giving out 2 dolls to Christel. Christel had 24 + 2 = 26 dolls after receiving 2 dolls from Debelyn. Christel had 24 - 5 = 19 dolls after giving Andrena 5 dolls. So, Andrena has 19 +2 = 21 dolls now. Therefore, Andrena has 21 - 18 = 3 more dolls than Debelyn."},
# ]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer.encode(prompt, return_tensors="pt")
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=4096)
print(tokenizer.decode(outputs[0]))
For vLLM:
from vllm import LLM, SamplingParams
llm = LLM(model=r'CogBase-USTC/SocraticLM',
tokenizer=r'CogBase-USTC/SocraticLM',
trust_remote_code=True,
tensor_parallel_size=1,
gpu_memory_utilization=0.99,
enable_chunked_prefill=True,
max_num_batched_tokens=512,
max_num_seqs=128)
sampling_params = SamplingParams(temperature=0, max_tokens=4096, seed=42)
def print_outputs(outputs):
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Generated text: {generated_text!r}")
print("-" * 80)
print("=" * 80)
### Math Problem Solving ###
conversation = [
{
"role": "system",
"content": "Please analyse and solve the following problem step by step."
},
{
"role": "user",
"content": "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?"
},
]
### Socratic-style Guidance ###
# conversation = [
# {
# "role": "system",
# "content": "You are a Socratic teacher, please guide me to solve the [Problem] with heuristic questions based on the following information. \n"
# },
# {
# "role": "user",
# "content": "[Problem] Debelyn, Christel, and Andrena collect dolls. Debelyn had 20 dolls before she gave Andrena 2 dolls. Christel had 24 dolls before giving Andrena 5 dolls. After all the gifts, Andrena now has 2 more dolls than Christel, how many more dolls does andrena have now than Debelyn? [Answer] 3 [Analysis] Debelyn had 20 - 2 = 18 dolls left after giving out 2 dolls to Christel. Christel had 24 + 2 = 26 dolls after receiving 2 dolls from Debelyn. Christel had 24 - 5 = 19 dolls after giving Andrena 5 dolls. So, Andrena has 19 +2 = 21 dolls now. Therefore, Andrena has 21 - 18 = 3 more dolls than Debelyn."
# },
# ]
outputs = llm.chat(conversation,
sampling_params=sampling_params,
use_tqdm=False,
)
print_outputs(outputs)
Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 1e-05
- train_batch_size: 8
- seed: 42
- distributed_type: multi-GPU
- num_devices: 4
- total_train_batch_size: 32
- total_eval_batch_size: 32
- optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: cosine
- lr_scheduler_warmup_steps: 20
Framework versions
- Transformers 4.46.2
- Pytorch 2.5.1+cu124
- Datasets 3.1.0
- Tokenizers 0.20.3
- Downloads last month
- 268
Collection including CogBase-USTC/SocraticLM
Collection
Enhanced Implementations of the paper: "SocraticLM: Exploring Socratic Personalized Teaching with Large Language Models" (NeurIPS'2024 Spotlight). • 4 items • Updated • 1