Instructions to use afoland/penchant-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use afoland/penchant-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="afoland/penchant-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("afoland/penchant-7B") model = AutoModelForCausalLM.from_pretrained("afoland/penchant-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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use afoland/penchant-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "afoland/penchant-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": "afoland/penchant-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/afoland/penchant-7B
- SGLang
How to use afoland/penchant-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 "afoland/penchant-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": "afoland/penchant-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 "afoland/penchant-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": "afoland/penchant-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use afoland/penchant-7B with Docker Model Runner:
docker model run hf.co/afoland/penchant-7B
File size: 2,220 Bytes
b67629f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import sys
import json
import random
from YOUR_API_CALLER_GOES_HERE import LLM_COMPLETION
def get_response(title, poet):
"""
Creates poem-generation prompt from title and poet, and puts it into
the expected penchant format
"""
penchant_prompt = f'Write an artistic poem. The title should be "{title}". Use vivid imagery and creative metaphors throughout your work. Draw inspiration from the works of {poet}. Pay close attention to the sounds that words make when read aloud, and use these sounds to create rhythm and musicality within your piece.'
penchant_template = f"<|im_start|>system\nYou are Dolphin, a helpful AI assistant.<|im_end|>\n<|im_start|>user\n{penchant_prompt}<|im_end|>\n<|im_start|>assistant\n"
poem = LLM_COMPLETION(penchant_template)
return poem
def process_files(titles_file, poets_file, output_file):
try:
# Read "titles" and "poets" from input files
with open(titles_file, 'r') as f:
titles_data = json.load(f)
titles = titles_data.get("titles", [])
with open(poets_file, 'r') as f:
poets_data = json.load(f)
poets = poets_data.get("poets", [])
# Write responses to output JSONL file
with open(output_file, 'w') as f:
poems_to_write = 100
count = 0
while count < poems_to_write:
title = random.choice(titles)
poet = random.choice(poets)
title = title.strip()
poet = poet.strip()
response = get_response(title, poet)
output_data = {"poet": poet, "title": title, "poem": response}
f.write(json.dumps(output_data) + "\n")
count += 1
except FileNotFoundError as e:
print(f"Error: {e.filename} not found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python script.py titles_file.json poets_file.json output_file.jsonl")
else:
titles_file = sys.argv[1]
poets_file = sys.argv[2]
output_file = sys.argv[3]
process_files(titles_file, poets_file, output_file)
|