Instructions to use yujiepan/gemma-tiny-random with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yujiepan/gemma-tiny-random with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yujiepan/gemma-tiny-random") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("yujiepan/gemma-tiny-random") model = AutoModelForCausalLM.from_pretrained("yujiepan/gemma-tiny-random") 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 yujiepan/gemma-tiny-random with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yujiepan/gemma-tiny-random" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yujiepan/gemma-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/yujiepan/gemma-tiny-random
- SGLang
How to use yujiepan/gemma-tiny-random 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 "yujiepan/gemma-tiny-random" \ --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": "yujiepan/gemma-tiny-random", "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 "yujiepan/gemma-tiny-random" \ --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": "yujiepan/gemma-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use yujiepan/gemma-tiny-random with Docker Model Runner:
docker model run hf.co/yujiepan/gemma-tiny-random
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: text-generation
|
| 3 |
+
inference: true
|
| 4 |
+
widget:
|
| 5 |
+
- text: 'Hello!'
|
| 6 |
+
example_title: Hello world
|
| 7 |
+
group: Python
|
| 8 |
+
library_name: transformers
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
This model is randomly initialized, using the config from [https://huggingface.co/google/gemma-7b] but with smaller size.
|
| 12 |
+
Note the model is in float16.
|
| 13 |
+
|
| 14 |
+
Codes:
|
| 15 |
+
```python
|
| 16 |
+
from transformers import pipeline
|
| 17 |
+
from huggingface_hub import create_repo, upload_folder
|
| 18 |
+
import torch
|
| 19 |
+
import transformers
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
model_id = 'google/gemma-7b'
|
| 23 |
+
save_path = '/tmp/yujiepan/gemma-tiny-random'
|
| 24 |
+
repo_id = 'yujiepan/gemma-tiny-random'
|
| 25 |
+
|
| 26 |
+
config = transformers.AutoConfig.from_pretrained(model_id)
|
| 27 |
+
config.hidden_size = 8
|
| 28 |
+
config.head_dim = 2
|
| 29 |
+
config.intermediate_size = 16
|
| 30 |
+
config.num_attention_heads = 4
|
| 31 |
+
config.num_hidden_layers = 2
|
| 32 |
+
config.num_key_value_heads = 2
|
| 33 |
+
print(config)
|
| 34 |
+
|
| 35 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
| 36 |
+
tokenizer.save_pretrained(save_path)
|
| 37 |
+
|
| 38 |
+
model = transformers.AutoModelForCausalLM.from_config(config, torch_dtype=torch.float16)
|
| 39 |
+
model = model.half()
|
| 40 |
+
|
| 41 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, do_sample=False, device='cuda')
|
| 42 |
+
print(pipe('Hello World!'))
|
| 43 |
+
|
| 44 |
+
model.save_pretrained(save_path)
|
| 45 |
+
|
| 46 |
+
# ovmodel = OVModelForCausalLM.from_pretrained(save_path, export=True)
|
| 47 |
+
# ovmodel = ovmodel.half()
|
| 48 |
+
# ovmodel.save_pretrained(save_path)
|
| 49 |
+
|
| 50 |
+
os.system(f'ls -alh {save_path}')
|
| 51 |
+
create_repo(repo_id, exist_ok=True)
|
| 52 |
+
upload_folder(repo_id=repo_id, folder_path=save_path)
|
| 53 |
+
```
|