Instructions to use HappyBulingling/MyModel-pretrain with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HappyBulingling/MyModel-pretrain with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HappyBulingling/MyModel-pretrain", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("HappyBulingling/MyModel-pretrain", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use HappyBulingling/MyModel-pretrain with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HappyBulingling/MyModel-pretrain" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HappyBulingling/MyModel-pretrain", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HappyBulingling/MyModel-pretrain
- SGLang
How to use HappyBulingling/MyModel-pretrain 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 "HappyBulingling/MyModel-pretrain" \ --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": "HappyBulingling/MyModel-pretrain", "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 "HappyBulingling/MyModel-pretrain" \ --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": "HappyBulingling/MyModel-pretrain", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use HappyBulingling/MyModel-pretrain with Docker Model Runner:
docker model run hf.co/HappyBulingling/MyModel-pretrain
Download rope.py from HappyBulingling/MyModel-pretrain: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/HappyBulingling/MyModel-pretrain/resolve/main/rope.py
- Command line
-
hf download hf://HappyBulingling/MyModel-pretrain/rope.py
-
curl -L -o rope.py https://huggingface.co/HappyBulingling/MyModel-pretrain/resolve/main/rope.py
1.15 kB
| """Rotary position embeddings.""" | |
| from __future__ import annotations | |
| import torch | |
| def precompute_rope( | |
| head_dim: int, | |
| max_position_embeddings: int, | |
| rope_theta: float, | |
| ) -> tuple[torch.Tensor, torch.Tensor]: | |
| if head_dim % 2 != 0: | |
| raise ValueError("head_dim must be even for RoPE") | |
| inv_freq = 1.0 / ( | |
| rope_theta ** (torch.arange(0, head_dim, 2, dtype=torch.float32) / head_dim) | |
| ) | |
| positions = torch.arange(max_position_embeddings, dtype=torch.float32) | |
| freqs = torch.outer(positions, inv_freq) | |
| emb = torch.cat((freqs, freqs), dim=-1) | |
| return emb.cos(), emb.sin() | |
| def rotate_half(x: torch.Tensor) -> torch.Tensor: | |
| half = x.shape[-1] // 2 | |
| return torch.cat((-x[..., half:], x[..., :half]), dim=-1) | |
| def apply_rotary_pos_emb( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| cos: torch.Tensor, | |
| sin: torch.Tensor, | |
| ) -> tuple[torch.Tensor, torch.Tensor]: | |
| cos = cos.to(q.device).unsqueeze(0).unsqueeze(2) | |
| sin = sin.to(q.device).unsqueeze(0).unsqueeze(2) | |
| q_embed = (q * cos) + (rotate_half(q) * sin) | |
| k_embed = (k * cos) + (rotate_half(k) * sin) | |
| return q_embed, k_embed | |