Quantifying the Carbon Emissions of Machine Learning
Paper • 1910.09700 • Published • 61
How to use sofanorai/sfnr-llm with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="sofanorai/sfnr-llm")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("sofanorai/sfnr-llm", device_map="auto")How to use sofanorai/sfnr-llm with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "sofanorai/sfnr-llm"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "sofanorai/sfnr-llm",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/sofanorai/sfnr-llm
How to use sofanorai/sfnr-llm with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "sofanorai/sfnr-llm" \
--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": "sofanorai/sfnr-llm",
"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 "sofanorai/sfnr-llm" \
--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": "sofanorai/sfnr-llm",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use sofanorai/sfnr-llm with Docker Model Runner:
docker model run hf.co/sofanorai/sfnr-llm
Use the code below to get started with the model.
pip install requests
import requests
HF_READ_TOKEN = "hf_token" # Use yor read-token, it is free
API_URL = "https://api-inference.huggingface.co/models/sofanorai/sofanor-7b"
headers = {"Authorization": f"Bearer {HF_READ_TOKEN}"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": "Can you please let us know more details about your ",
})
python your_file.py
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).