Instructions to use theblackcat102/galactica-1.3b-conversation-finetuned with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use theblackcat102/galactica-1.3b-conversation-finetuned with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="theblackcat102/galactica-1.3b-conversation-finetuned")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("theblackcat102/galactica-1.3b-conversation-finetuned") model = AutoModelForCausalLM.from_pretrained("theblackcat102/galactica-1.3b-conversation-finetuned", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use theblackcat102/galactica-1.3b-conversation-finetuned with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "theblackcat102/galactica-1.3b-conversation-finetuned" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "theblackcat102/galactica-1.3b-conversation-finetuned", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/theblackcat102/galactica-1.3b-conversation-finetuned
- SGLang
How to use theblackcat102/galactica-1.3b-conversation-finetuned 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 "theblackcat102/galactica-1.3b-conversation-finetuned" \ --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": "theblackcat102/galactica-1.3b-conversation-finetuned", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "theblackcat102/galactica-1.3b-conversation-finetuned" \ --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": "theblackcat102/galactica-1.3b-conversation-finetuned", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use theblackcat102/galactica-1.3b-conversation-finetuned with Docker Model Runner:
docker model run hf.co/theblackcat102/galactica-1.3b-conversation-finetuned
Supervised Finetuning demonstration
Models are finetuned on generated conversation curated from the Open Assistant.
Mixing reward model with sampling
We can use reward model to rank the best answer using this example code:
import torch
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("facebook/galactica-1.3b-base-finetuned/checkpoint-1000")
model = AutoModelForCausalLM.from_pretrained("facebook/galactica-1.3b-base-finetuned/checkpoint-1000").eval().half().cuda()
reward_name = "theblackcat102/electra-large-reward-model"
rank_model, rank_tokenizer = AutoModelForSequenceClassification.from_pretrained(reward_name), AutoTokenizer.from_pretrained(reward_name)
rank_model = rank_model.eval().half().cuda()
questions = ["<question>How do I make a resume?<answer>"]
for question in questions:
inputs = tokenizer(question, return_tensors="pt", padding=True).to(0)
if 'token_type_ids' in inputs:
inputs.pop('token_type_ids')
outputs = model.generate(**inputs, do_sample=True,
top_k=60,
max_length=220,
num_return_sequences=80,
early_stopping=True
)
print(question)
results = []
for i, beam_output in enumerate(outputs):
output = tokenizer.decode(beam_output, truncate_before_pattern=[r"\n\n^#", "^'''", "\n\n\n"])
question, answer = output.split('<answer>', maxsplit=1)
answer = answer.split('<question>')[0].replace('<|endoftext|>', '').lstrip().split('<answer>')[0]
rank_inputs = rank_tokenizer(question, answer, return_tensors="pt", padding=True, max_length=512, truncation=True).to(1)
score = rank_model(**rank_inputs).logits[0].cpu().detach()
results.append((answer, score, output))
full_results[question] = results
sorted_result = sorted(results, key=lambda x:x[1], reverse=True)
total_scores += sorted_result[0][1].item()
print('score',sorted_result[0][1].item())
print('-----Best rank-----')
print(sorted_result[0][0])
print('-------------------')
Checkout weights and biases report for training detail.
Thanks to BASIC lab for compute resource. BASIC Lab is an academic research lab which focuses in multi-modality learning and data mining domain.
- Downloads last month
- 11