Salesforce/xlam-function-calling-60k
Viewer • Updated • 60k • 22.9k • 618
How to use akshayballal/gemma2-2b-xlam-function-calling with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-2-2b-bnb-4bit")
model = PeftModel.from_pretrained(base_model, "akshayballal/gemma2-2b-xlam-function-calling")How to use akshayballal/gemma2-2b-xlam-function-calling with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="akshayballal/gemma2-2b-xlam-function-calling") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("akshayballal/gemma2-2b-xlam-function-calling", dtype="auto")How to use akshayballal/gemma2-2b-xlam-function-calling with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "akshayballal/gemma2-2b-xlam-function-calling"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "akshayballal/gemma2-2b-xlam-function-calling",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/akshayballal/gemma2-2b-xlam-function-calling
How to use akshayballal/gemma2-2b-xlam-function-calling with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "akshayballal/gemma2-2b-xlam-function-calling" \
--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": "akshayballal/gemma2-2b-xlam-function-calling",
"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 "akshayballal/gemma2-2b-xlam-function-calling" \
--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": "akshayballal/gemma2-2b-xlam-function-calling",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use akshayballal/gemma2-2b-xlam-function-calling with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for akshayballal/gemma2-2b-xlam-function-calling to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for akshayballal/gemma2-2b-xlam-function-calling to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for akshayballal/gemma2-2b-xlam-function-calling to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="akshayballal/gemma2-2b-xlam-function-calling",
max_seq_length=2048,
)How to use akshayballal/gemma2-2b-xlam-function-calling with Docker Model Runner:
docker model run hf.co/akshayballal/gemma2-2b-xlam-function-calling
This model is a function calling version of google/gemma-2-2b finetuned on the Salesforce/xlam-function-calling-60k dataset.
from unsloth import FastLanguageModel
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "gemma2-2b-xlam-function-calling", # YOUR MODEL YOU USED FOR TRAINING
max_seq_length = 1024,
dtype = dtype,
load_in_4bit = load_in_4bit,
)
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
alpaca_prompt = """Below are the tools that you have access to these tools. Use them if required.
### Tools:
{}
### Query:
{}
### Response:
{}"""
tools = [
{
"name": "upcoming",
"description": "Fetches upcoming CS:GO matches data from the specified API endpoint.",
"parameters": {
"content_type": {
"description": "The content type for the request, default is 'application/json'.",
"type": "str",
"default": "application/json",
},
"page": {
"description": "The page number to retrieve, default is 1.",
"type": "int",
"default": "1",
},
"limit": {
"description": "The number of matches to retrieve per page, default is 10.",
"type": "int",
"default": "10",
},
},
}
]
query = """Can you fetch the upcoming CS:GO matches for page 1 with a 'text/xml' content type and a limit of 20 matches? Also, can you fetch the upcoming matches for page 2 with the 'application/xml' content type and a limit of 15 matches?"""
FastLanguageModel.for_inference(model)
model_input = tokenizer(alpaca_prompt.format(tools, query, ""), return_tensors="pt")
output = model.generate(**input, max_new_tokens=1024, temperature = 0.0)
decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)