Instructions to use alibidaran/Gemma2_Python_instruction with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alibidaran/Gemma2_Python_instruction with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="alibidaran/Gemma2_Python_instruction")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("alibidaran/Gemma2_Python_instruction") model = AutoModelForCausalLM.from_pretrained("alibidaran/Gemma2_Python_instruction") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use alibidaran/Gemma2_Python_instruction with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "alibidaran/Gemma2_Python_instruction" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alibidaran/Gemma2_Python_instruction", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/alibidaran/Gemma2_Python_instruction
- SGLang
How to use alibidaran/Gemma2_Python_instruction 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 "alibidaran/Gemma2_Python_instruction" \ --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": "alibidaran/Gemma2_Python_instruction", "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 "alibidaran/Gemma2_Python_instruction" \ --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": "alibidaran/Gemma2_Python_instruction", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use alibidaran/Gemma2_Python_instruction with Docker Model Runner:
docker model run hf.co/alibidaran/Gemma2_Python_instruction
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("alibidaran/Gemma2_Python_instruction")
model = AutoModelForCausalLM.from_pretrained("alibidaran/Gemma2_Python_instruction")Model Card for Model ID
Model Details
Model Description
This model is fined-tuned based of Gemma model by Google's Gemini family and trained for generating general python codes, from Machine learning, to Web developing and data processing.
Developed by: Ali Bidaran
Language(s) (NLP): English
Uses
This model can be used for generating python codes in different usages such as data processing, designing ML and DL algorithms and implementing the backends of web applications with common frameworks such as Flask. Users can obtain the generated text by giving required prompts and instructions to the model.
Direct Use
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, GemmaTokenizer
model_id = "alibidaran/Gemma2_Python_instruction"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map={"":0})
prompt = """
Connect to a MongoDB database, select all documents from the collection ‘customers’ where the 'age' field is greater than 30 and the 'gender' field is 'female'. Then, for each selected document, retrieve the corresponding document from another collection called 'orders' based on the 'customer_id' field. Finally, display the documents in ascending order based on the 'last_name' field. The expected time complexity for retrieving the documents from the 'customers' collection should be O(n), where n is the total number of documents in the collection. The expected time complexity for retrieving the corresponding documents from the 'orders' collection for each selected document should also be O(n), where n is the total number of selected documents.
"""
text=f"<s> ##Instruction: {prompt}: ##Output "
inputs=tokenizer(text,return_tensors='pt').to('cuda')
outputs=model.generate(**inputs,max_new_tokens=400,do_sample=True,top_p=0.92,top_k=10,temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
[More Information Needed]
- Downloads last month
- 3
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="alibidaran/Gemma2_Python_instruction")