Instructions to use shahdishank/gemma-2b-it-finetune-python-codes with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shahdishank/gemma-2b-it-finetune-python-codes with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shahdishank/gemma-2b-it-finetune-python-codes") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("shahdishank/gemma-2b-it-finetune-python-codes") model = AutoModelForCausalLM.from_pretrained("shahdishank/gemma-2b-it-finetune-python-codes") 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
- vLLM
How to use shahdishank/gemma-2b-it-finetune-python-codes with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shahdishank/gemma-2b-it-finetune-python-codes" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shahdishank/gemma-2b-it-finetune-python-codes", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/shahdishank/gemma-2b-it-finetune-python-codes
- SGLang
How to use shahdishank/gemma-2b-it-finetune-python-codes 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 "shahdishank/gemma-2b-it-finetune-python-codes" \ --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": "shahdishank/gemma-2b-it-finetune-python-codes", "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 "shahdishank/gemma-2b-it-finetune-python-codes" \ --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": "shahdishank/gemma-2b-it-finetune-python-codes", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use shahdishank/gemma-2b-it-finetune-python-codes with Docker Model Runner:
docker model run hf.co/shahdishank/gemma-2b-it-finetune-python-codes
updated Readme
Browse files
README.md
CHANGED
|
@@ -14,4 +14,75 @@ widget:
|
|
| 14 |
language:
|
| 15 |
- en
|
| 16 |
pipeline_tag: text-generation
|
| 17 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
language:
|
| 15 |
- en
|
| 16 |
pipeline_tag: text-generation
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# Gemma-2b-it-finetuned-python-codes
|
| 20 |
+
|
| 21 |
+
This model card corresponds to the 2B finetuned version of the Gemma-2b-it model. You can visit the model card of the [2B Gemma Instruct](https://huggingface.co/google/gemma-2b-it).
|
| 22 |
+
|
| 23 |
+
**Author**: Dishank Shah
|
| 24 |
+
|
| 25 |
+
## Model Information
|
| 26 |
+
|
| 27 |
+
Summary description and brief definition of inputs and outputs.
|
| 28 |
+
|
| 29 |
+
### Description
|
| 30 |
+
|
| 31 |
+
Gemma is a family of lightweight, state-of-the-art open models from Google,
|
| 32 |
+
built from the same research and technology used to create the Gemini models.
|
| 33 |
+
They are text-to-text, decoder-only large language models, available in English,
|
| 34 |
+
with open weights, pre-trained variants, and instruction-tuned variants. Gemma
|
| 35 |
+
models are well-suited for a variety of text generation tasks, including
|
| 36 |
+
question answering, summarization, and reasoning. Their relatively small size
|
| 37 |
+
makes it possible to deploy them in environments with limited resources such as
|
| 38 |
+
a laptop, desktop or your own cloud infrastructure, democratizing access to
|
| 39 |
+
state of the art AI models and helping foster innovation for everyone.
|
| 40 |
+
|
| 41 |
+
### Usage
|
| 42 |
+
|
| 43 |
+
Below we share some code snippets on how to get quickly started with running the model. First make sure to `pip install -U transformers`, then copy the snippet from the section that is relevant for your usecase.
|
| 44 |
+
|
| 45 |
+
#### Running the model on Google Colab CPU
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 49 |
+
|
| 50 |
+
model_name = "shahdishank/gemma-2b-it-finetune-python-codes"
|
| 51 |
+
HUGGING_FACE_TOKEN = "YOUR_TOKEN"
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, token="HUGGING_FACE_TOKEN")
|
| 53 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, token="HUGGING_FACE_TOKEN")
|
| 54 |
+
|
| 55 |
+
prompt_template = """\
|
| 56 |
+
user:\n{query} \n\n assistant:\n
|
| 57 |
+
"""
|
| 58 |
+
prompt = prompt_template.format(query="write a simple python function") # write your query here
|
| 59 |
+
|
| 60 |
+
input_ids = tokenizer(prompt, return_tensors="pt", add_special_tokens=True)
|
| 61 |
+
outputs = model.generate(**input_ids, max_new_tokens=2000, do_sample=True, pad_token_id=tokenizer.eos_token_id)
|
| 62 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 63 |
+
print(response)
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## Model Data
|
| 67 |
+
|
| 68 |
+
Data used for model training [python-codes-25k](https://huggingface.co/datasets/flytech/python-codes-25k).
|
| 69 |
+
|
| 70 |
+
### Training Dataset
|
| 71 |
+
|
| 72 |
+
These models were trained on a dataset of text data that includes a wide variety
|
| 73 |
+
of python codes. Here are the key components:
|
| 74 |
+
|
| 75 |
+
* Instruction: The instructional task to be performed / User input.
|
| 76 |
+
* Input: Very short, introductive part of AI response or empty.
|
| 77 |
+
* Output: Python code that accomplishes the task.
|
| 78 |
+
* Text: All fields combined together.
|
| 79 |
+
|
| 80 |
+
This diverse data source is crucial for training a powerful
|
| 81 |
+
language model that can handle a wide variety of different tasks.
|
| 82 |
+
|
| 83 |
+
### Usage
|
| 84 |
+
|
| 85 |
+
This LLM can be used for:
|
| 86 |
+
* Code generation
|
| 87 |
+
* Debugging
|
| 88 |
+
* Learn and understand various python coding styles
|