Text Generation
Transformers
Safetensors
code
gemma
Generated from Trainer
coding
text-generation-inference
Instructions to use MAISAAI/gemma-2b-coder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MAISAAI/gemma-2b-coder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="MAISAAI/gemma-2b-coder")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("MAISAAI/gemma-2b-coder") model = AutoModelForCausalLM.from_pretrained("MAISAAI/gemma-2b-coder") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use MAISAAI/gemma-2b-coder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MAISAAI/gemma-2b-coder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MAISAAI/gemma-2b-coder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/MAISAAI/gemma-2b-coder
- SGLang
How to use MAISAAI/gemma-2b-coder 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 "MAISAAI/gemma-2b-coder" \ --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": "MAISAAI/gemma-2b-coder", "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 "MAISAAI/gemma-2b-coder" \ --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": "MAISAAI/gemma-2b-coder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use MAISAAI/gemma-2b-coder with Docker Model Runner:
docker model run hf.co/MAISAAI/gemma-2b-coder
Update README.md
Browse files
README.md
CHANGED
|
@@ -21,7 +21,7 @@ pipeline_tag: text-generation
|
|
| 21 |
</div>
|
| 22 |
|
| 23 |
|
| 24 |
-
# Gemma Coder
|
| 25 |
**Gemma 2B** fine-tuned on the **CodeAlpaca 20k instructions dataset** by using the method **QLoRA** with [PEFT](https://github.com/huggingface/peft) library.
|
| 26 |
|
| 27 |
## Model description 🧠
|
|
@@ -95,15 +95,15 @@ def create_prompt(instruction):
|
|
| 95 |
|
| 96 |
def generate(
|
| 97 |
instruction,
|
| 98 |
-
max_new_tokens=
|
| 99 |
temperature=0.1,
|
| 100 |
top_p=0.75,
|
| 101 |
top_k=40,
|
| 102 |
-
num_beams=
|
| 103 |
**kwargs,
|
| 104 |
):
|
| 105 |
-
|
| 106 |
-
|
| 107 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 108 |
input_ids = inputs["input_ids"].to("cuda")
|
| 109 |
attention_mask = inputs["attention_mask"].to("cuda")
|
|
@@ -120,13 +120,13 @@ def generate(
|
|
| 120 |
attention_mask=attention_mask,
|
| 121 |
generation_config=generation_config,
|
| 122 |
return_dict_in_generate=True,
|
| 123 |
-
output_scores=True,
|
| 124 |
max_new_tokens=max_new_tokens,
|
| 125 |
early_stopping=True
|
| 126 |
)
|
| 127 |
s = generation_output.sequences[0]
|
| 128 |
-
output = tokenizer.decode(s)
|
| 129 |
-
return output.split("
|
| 130 |
|
| 131 |
instruction = """
|
| 132 |
Edit the following XML code to add a navigation bar to the top of a web page
|
|
|
|
| 21 |
</div>
|
| 22 |
|
| 23 |
|
| 24 |
+
# Gemma Coder 👩💻
|
| 25 |
**Gemma 2B** fine-tuned on the **CodeAlpaca 20k instructions dataset** by using the method **QLoRA** with [PEFT](https://github.com/huggingface/peft) library.
|
| 26 |
|
| 27 |
## Model description 🧠
|
|
|
|
| 95 |
|
| 96 |
def generate(
|
| 97 |
instruction,
|
| 98 |
+
max_new_tokens=256,
|
| 99 |
temperature=0.1,
|
| 100 |
top_p=0.75,
|
| 101 |
top_k=40,
|
| 102 |
+
num_beams=2,
|
| 103 |
**kwargs,
|
| 104 |
):
|
| 105 |
+
system = f"<bos><|system|>\nYou are a helpful coding assistant.<eos>\n"
|
| 106 |
+
prompt = f"{system}<|user|>\n{instruction}<eos>\n<|assistant|>\n"
|
| 107 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 108 |
input_ids = inputs["input_ids"].to("cuda")
|
| 109 |
attention_mask = inputs["attention_mask"].to("cuda")
|
|
|
|
| 120 |
attention_mask=attention_mask,
|
| 121 |
generation_config=generation_config,
|
| 122 |
return_dict_in_generate=True,
|
| 123 |
+
#output_scores=True,
|
| 124 |
max_new_tokens=max_new_tokens,
|
| 125 |
early_stopping=True
|
| 126 |
)
|
| 127 |
s = generation_output.sequences[0]
|
| 128 |
+
output = tokenizer.decode(s, skip_special_tokens=True)
|
| 129 |
+
return output.split("<|assistant|>")[1]
|
| 130 |
|
| 131 |
instruction = """
|
| 132 |
Edit the following XML code to add a navigation bar to the top of a web page
|