Instructions to use HappyBulingling/MyModel-sft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HappyBulingling/MyModel-sft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HappyBulingling/MyModel-sft", 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-sft", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use HappyBulingling/MyModel-sft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HappyBulingling/MyModel-sft" # 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-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HappyBulingling/MyModel-sft
- SGLang
How to use HappyBulingling/MyModel-sft 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-sft" \ --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-sft", "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-sft" \ --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-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use HappyBulingling/MyModel-sft with Docker Model Runner:
docker model run hf.co/HappyBulingling/MyModel-sft
Download block.py from HappyBulingling/MyModel-sft: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/HappyBulingling/MyModel-sft/resolve/main/block.py
- Command line
-
hf download hf://HappyBulingling/MyModel-sft/block.py
-
curl -L -o block.py https://huggingface.co/HappyBulingling/MyModel-sft/resolve/main/block.py
2.18 kB
| """Transformer block: pre-norm GQA + SwiGLU with two residual paths.""" | |
| from __future__ import annotations | |
| import torch | |
| from torch import nn | |
| from transformers.activations import ACT2FN | |
| from .attention import Attention | |
| from .config import MyModelConfig | |
| from .norm import RMSNorm | |
| class FeedForward(nn.Module): | |
| def __init__(self, config: MyModelConfig): | |
| super().__init__() | |
| self.gate_proj = nn.Linear( | |
| config.hidden_size, | |
| config.intermediate_size, | |
| bias=config.mlp_bias, | |
| ) | |
| self.up_proj = nn.Linear( | |
| config.hidden_size, | |
| config.intermediate_size, | |
| bias=config.mlp_bias, | |
| ) | |
| self.down_proj = nn.Linear( | |
| config.intermediate_size, | |
| config.hidden_size, | |
| bias=config.mlp_bias, | |
| ) | |
| self.act_fn = ACT2FN[config.hidden_act] | |
| def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: | |
| return self.down_proj(self.act_fn(self.gate_proj(hidden_states)) * self.up_proj(hidden_states)) | |
| class Block(nn.Module): | |
| def __init__(self, config: MyModelConfig): | |
| super().__init__() | |
| self.input_layernorm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps) | |
| self.self_attn = Attention(config) | |
| self.post_attention_layernorm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps) | |
| self.mlp = FeedForward(config) | |
| def forward( | |
| self, | |
| hidden_states: torch.Tensor, | |
| cos: torch.Tensor, | |
| sin: torch.Tensor, | |
| past_key_value: tuple[torch.Tensor, torch.Tensor] | None = None, | |
| use_cache: bool = False, | |
| attention_mask: torch.Tensor | None = None, | |
| ) -> tuple[torch.Tensor, tuple[torch.Tensor, torch.Tensor] | None]: | |
| attention_output, present = self.self_attn( | |
| self.input_layernorm(hidden_states), | |
| cos, | |
| sin, | |
| past_key_value, | |
| use_cache, | |
| attention_mask, | |
| ) | |
| hidden_states = hidden_states + attention_output | |
| hidden_states = hidden_states + self.mlp(self.post_attention_layernorm(hidden_states)) | |
| return hidden_states, present | |