Instructions to use TechxGenus/CodeGemma-2b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TechxGenus/CodeGemma-2b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TechxGenus/CodeGemma-2b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CodeGemma-2b") model = AutoModelForCausalLM.from_pretrained("TechxGenus/CodeGemma-2b") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TechxGenus/CodeGemma-2b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TechxGenus/CodeGemma-2b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TechxGenus/CodeGemma-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/TechxGenus/CodeGemma-2b
- SGLang
How to use TechxGenus/CodeGemma-2b 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 "TechxGenus/CodeGemma-2b" \ --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": "TechxGenus/CodeGemma-2b", "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 "TechxGenus/CodeGemma-2b" \ --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": "TechxGenus/CodeGemma-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use TechxGenus/CodeGemma-2b with Docker Model Runner:
docker model run hf.co/TechxGenus/CodeGemma-2b
Upload README.md
Browse files
README.md
CHANGED
|
@@ -19,10 +19,10 @@ We've fine-tuned Gemma-2b with an additional 0.7 billion high-quality, code-rela
|
|
| 19 |
|
| 20 |
### Usage
|
| 21 |
|
| 22 |
-
Here give
|
| 23 |
|
| 24 |
```python
|
| 25 |
-
from transformers import
|
| 26 |
import torch
|
| 27 |
PROMPT = """### Instruction
|
| 28 |
{instruction}
|
|
@@ -30,6 +30,29 @@ PROMPT = """### Instruction
|
|
| 30 |
"""
|
| 31 |
instruction = <Your code instruction here>
|
| 32 |
prompt = PROMPT.format(instruction=instruction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
generator = pipeline(
|
| 34 |
model="TechxGenus/CodeGemma-2b",
|
| 35 |
task="text-generation",
|
|
|
|
| 19 |
|
| 20 |
### Usage
|
| 21 |
|
| 22 |
+
Here give some examples of how to use our model:
|
| 23 |
|
| 24 |
```python
|
| 25 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 26 |
import torch
|
| 27 |
PROMPT = """### Instruction
|
| 28 |
{instruction}
|
|
|
|
| 30 |
"""
|
| 31 |
instruction = <Your code instruction here>
|
| 32 |
prompt = PROMPT.format(instruction=instruction)
|
| 33 |
+
tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CodeGemma-2b")
|
| 34 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 35 |
+
"TechxGenus/CodeGemma-2b",
|
| 36 |
+
torch_dtype=torch.bfloat16,
|
| 37 |
+
device_map="auto",
|
| 38 |
+
)
|
| 39 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
| 40 |
+
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=2048)
|
| 41 |
+
print(tokenizer.decode(outputs[0]))
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
With text-generation pipeline:
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from transformers import pipeline
|
| 49 |
+
import torch
|
| 50 |
+
PROMPT = """<bos>### Instruction
|
| 51 |
+
{instruction}
|
| 52 |
+
### Response
|
| 53 |
+
"""
|
| 54 |
+
instruction = <Your code instruction here>
|
| 55 |
+
prompt = PROMPT.format(instruction=instruction)
|
| 56 |
generator = pipeline(
|
| 57 |
model="TechxGenus/CodeGemma-2b",
|
| 58 |
task="text-generation",
|