Instructions to use hf-internal-testing/tiny-random-Gemma2ForCausalLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hf-internal-testing/tiny-random-Gemma2ForCausalLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hf-internal-testing/tiny-random-Gemma2ForCausalLM")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-Gemma2ForCausalLM") model = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-Gemma2ForCausalLM") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use hf-internal-testing/tiny-random-Gemma2ForCausalLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hf-internal-testing/tiny-random-Gemma2ForCausalLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hf-internal-testing/tiny-random-Gemma2ForCausalLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/hf-internal-testing/tiny-random-Gemma2ForCausalLM
- SGLang
How to use hf-internal-testing/tiny-random-Gemma2ForCausalLM 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 "hf-internal-testing/tiny-random-Gemma2ForCausalLM" \ --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": "hf-internal-testing/tiny-random-Gemma2ForCausalLM", "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 "hf-internal-testing/tiny-random-Gemma2ForCausalLM" \ --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": "hf-internal-testing/tiny-random-Gemma2ForCausalLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use hf-internal-testing/tiny-random-Gemma2ForCausalLM with Docker Model Runner:
docker model run hf.co/hf-internal-testing/tiny-random-Gemma2ForCausalLM
Update README.md
Browse files
README.md
CHANGED
|
@@ -11,6 +11,41 @@ tags: []
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
### Model Description
|
| 15 |
|
| 16 |
<!-- Provide a longer summary of what this model is. -->
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
+
Tiny `Gemma2ForCausalLM` with randomly-initialized weights for testing. Code to generate:
|
| 15 |
+
```py
|
| 16 |
+
import torch
|
| 17 |
+
from transformers import Gemma2ForCausalLM, Gemma2Config, AutoTokenizer
|
| 18 |
+
|
| 19 |
+
# Set seed for reproducibility
|
| 20 |
+
torch.manual_seed(0)
|
| 21 |
+
|
| 22 |
+
# Initializing a Gemma2 gemma2-9b style configuration
|
| 23 |
+
configuration = Gemma2Config(
|
| 24 |
+
head_dim=16,
|
| 25 |
+
hidden_size=32,
|
| 26 |
+
initializer_range=0.02,
|
| 27 |
+
intermediate_size=64,
|
| 28 |
+
max_position_embeddings=8192,
|
| 29 |
+
model_type="gemma2",
|
| 30 |
+
num_attention_heads=2,
|
| 31 |
+
num_hidden_layers=1,
|
| 32 |
+
num_key_value_heads=2,
|
| 33 |
+
vocab_size=256000,
|
| 34 |
+
attn_implementation='eager',
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Initializing a model from the gemma2-9b style configuration
|
| 38 |
+
model = Gemma2ForCausalLM(configuration)
|
| 39 |
+
|
| 40 |
+
# Re-use gemma2 tokenizer
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained("Xenova/gemma2-tokenizer")
|
| 42 |
+
|
| 43 |
+
# Upload to the HF Hub
|
| 44 |
+
model_id = 'hf-internal-testing/tiny-random-Gemma2ForCausalLM'
|
| 45 |
+
model.push_to_hub(model_id)
|
| 46 |
+
tokenizer.push_to_hub(model_id)
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
### Model Description
|
| 50 |
|
| 51 |
<!-- Provide a longer summary of what this model is. -->
|