stfotso/french-ghomala-bandjoun
Viewer • Updated • 15.2k • 32 • 3
How to use stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
model = AutoModelForCausalLM.from_pretrained("stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
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]:]))How to use stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B
How to use stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B" \
--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": "stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B" \
--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": "stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B with Docker Model Runner:
docker model run hf.co/stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
model = AutoModelForCausalLM.from_pretrained("stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
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]:]))Translates sentences from French to Ghomala, native language of Bandjoun, a cameroonian village.
Example:
from transformers import AutoTokenizer, AutoModelForCausalLM
MAX_TOKENS = 256
tokenizer = AutoTokenizer.from_pretrained("stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
model = AutoModelForCausalLM.from_pretrained("stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B")
test_sentence = "bonjour Adam"
print(test_sentence)
system_prompt = """
1. You are a helpful specialist in linguistic, especially african language and you are required to provide the rightfull translation of a french expression into the ghomala language, the native language of bandjoun, a village of Cameroon.
2. Your ghomala translation should use correct phonetic signs.
"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "Sentence (in french): <s>vieil homme</s>"},
{"role": "assistant", "content": "Sentence (in ghomala): <s>bvo</s>"},
{"role": "user", "content": f"Sentence (in french): <s>{test_sentence}</s>"}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer.encode(prompt, return_tensors="pt")
outputs = model.generate(inputs, max_length=MAX_TOKENS, tokenizer=tokenizer, do_sample=True, temperature=0.5, top_p=1, top_k=50, stop_strings=["Sentence (in french)", "</s>"], pad_token_id=tokenizer.eos_token_id)
generated_text = tokenizer.batch_decode(outputs[:, inputs.shape[1]:])[0]
print(f'generated text: {generated_text}')
Base model
meta-llama/Llama-3.2-1B-Instruct
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="stfotso/llama-3.2-tuned-french-ghomala-bandjoun-1B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)