kaist-ai/CoT-Collection
Viewer • Updated • 1.84M • 1.05k • 159
How to use w601sxs/b1ade-1b-bf16 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="w601sxs/b1ade-1b-bf16") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("w601sxs/b1ade-1b-bf16")
model = AutoModelForCausalLM.from_pretrained("w601sxs/b1ade-1b-bf16")How to use w601sxs/b1ade-1b-bf16 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "w601sxs/b1ade-1b-bf16"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "w601sxs/b1ade-1b-bf16",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/w601sxs/b1ade-1b-bf16
How to use w601sxs/b1ade-1b-bf16 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "w601sxs/b1ade-1b-bf16" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "w601sxs/b1ade-1b-bf16",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "w601sxs/b1ade-1b-bf16" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "w601sxs/b1ade-1b-bf16",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use w601sxs/b1ade-1b-bf16 with Docker Model Runner:
docker model run hf.co/w601sxs/b1ade-1b-bf16
Instruction fine tuned 1B parameter model; pass in:
context: <...>question: <...> and expect an answer: <...>
See implemetation example below (also see https://huggingface.co/spaces/w601sxs/b1ade-1b):
import torch
import transformers
import os, time
import tempfile
from transformers import AutoTokenizer, AutoModelForCausalLM
BASE_MODEL = "w601sxs/b1ade-1b-bf16"
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
model = AutoModelForCausalLM.from_pretrained(BASE_MODEL,
torch_dtype=torch.bfloat16,
device_map="auto",
offload_folder="offload")
model.eval()
from transformers import StoppingCriteria, AutoModelForCausalLM, AutoTokenizer, StoppingCriteriaList
class KeywordsStoppingCriteria(StoppingCriteria):
def __init__(self, keywords_ids:list):
self.keywords = keywords_ids
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
if input_ids[0][-1] in self.keywords:
return True
return False
stop_words = ['>', ' >','> ']
stop_ids = [tokenizer.encode(w)[0] for w in stop_words]
stop_criteria = StoppingCriteriaList([KeywordsStoppingCriteria(keywords_ids = stop_ids)])
def predict(text):
inputs = tokenizer(text, return_tensors="pt").to('cuda')
with torch.no_grad():
outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=128, stopping_criteria=stop_criteria)
out_text = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0].split("answer:")[-1]
return print(out_text.split(text)[-1])
predict("context: <The center contact of the bulb typically connects to the medium-power filament, and the ring connects to the low-power filament. Thus, if a 3-way bulb is screwed into a standard light socket that has only a center contact, only the medium-power filament operates. In the case of the 50 W / 100 W / 150 W bulb, putting this bulb in a regular lamp socket will result in it behaving like a normal 100W bulb.>\n question: <Question: Do 3 way light bulbs work in any lamp?>\n")