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 config.py from HappyBulingling/MyModel-pretrain: direct link, hf CLI and curl.
- Browser
- Download file 4.5 kB
-
https://huggingface.co/HappyBulingling/MyModel-pretrain/resolve/main/config.py
- Command line
-
hf download hf://HappyBulingling/MyModel-pretrain/config.py
-
curl -L -o config.py https://huggingface.co/HappyBulingling/MyModel-pretrain/resolve/main/config.py
4.5 kB
| """Model configuration and the two presets used by this project.""" | |
| from __future__ import annotations | |
| from transformers import PretrainedConfig | |
| PRESETS = { | |
| "tiny": { | |
| "hidden_size": 256, | |
| "num_hidden_layers": 4, | |
| "num_attention_heads": 8, | |
| "num_key_value_heads": 1, | |
| "head_dim": 32, | |
| "intermediate_size": 896, | |
| "vocab_size": 32768, | |
| }, | |
| "base": { | |
| "hidden_size": 1024, | |
| "num_hidden_layers": 20, | |
| "num_attention_heads": 16, | |
| "num_key_value_heads": 4, | |
| "head_dim": 64, | |
| "intermediate_size": 2816, | |
| "vocab_size": 32768, | |
| }, | |
| } | |
| class MyModelConfig(PretrainedConfig): | |
| """Configuration for the 259M dense text backbone. | |
| Defaults: 20 layers, d=1024, GQA 16:4, SwiGLU 2816, 32K vocabulary, | |
| tied embeddings. | |
| """ | |
| model_type = "mymodel" | |
| def __init__( | |
| self, | |
| hidden_size: int = 1024, | |
| num_hidden_layers: int = 20, | |
| num_attention_heads: int = 16, | |
| num_key_value_heads: int = 4, | |
| head_dim: int = 64, | |
| intermediate_size: int = 2816, | |
| vocab_size: int = 32768, | |
| hidden_act: str = "silu", | |
| rms_norm_eps: float = 1e-6, | |
| qk_norm: bool = True, | |
| rope_theta: float = 1_000_000.0, | |
| max_position_embeddings: int = 4096, | |
| rope_scaling: dict | None = None, | |
| tie_word_embeddings: bool = True, | |
| attention_bias: bool = False, | |
| mlp_bias: bool = False, | |
| dropout: float = 0.0, | |
| ffn_type: str = "dense", | |
| parametrization: str = "standard", | |
| initializer_range: float = 0.02, | |
| bos_token_id: int = 2, | |
| eos_token_id: int = 0, | |
| im_end_token_id: int = 5, | |
| pad_token_id: int = 1, | |
| unk_token_id: int = 3, | |
| **kwargs, | |
| ): | |
| super().__init__( | |
| bos_token_id=bos_token_id, | |
| eos_token_id=eos_token_id, | |
| pad_token_id=pad_token_id, | |
| unk_token_id=unk_token_id, | |
| tie_word_embeddings=tie_word_embeddings, | |
| **kwargs, | |
| ) | |
| self.im_end_token_id = im_end_token_id | |
| if hidden_size % num_attention_heads != 0: | |
| raise ValueError("hidden_size must be divisible by num_attention_heads") | |
| if num_attention_heads % num_key_value_heads != 0: | |
| raise ValueError("num_attention_heads must be divisible by num_key_value_heads") | |
| if head_dim * num_attention_heads != hidden_size: | |
| raise ValueError("head_dim * num_attention_heads must equal hidden_size") | |
| self.hidden_size = hidden_size | |
| self.num_hidden_layers = num_hidden_layers | |
| self.num_attention_heads = num_attention_heads | |
| self.num_key_value_heads = num_key_value_heads | |
| self.head_dim = head_dim | |
| self.intermediate_size = intermediate_size | |
| self.vocab_size = vocab_size | |
| self.hidden_act = hidden_act | |
| self.rms_norm_eps = rms_norm_eps | |
| self.qk_norm = qk_norm | |
| self.rope_theta = rope_theta | |
| self.max_position_embeddings = max_position_embeddings | |
| self.rope_scaling = rope_scaling | |
| self.attention_bias = attention_bias | |
| self.mlp_bias = mlp_bias | |
| self.dropout = dropout | |
| self.ffn_type = ffn_type | |
| self.parametrization = parametrization | |
| self.initializer_range = initializer_range | |
| if self.ffn_type != "dense": | |
| raise ValueError(f"unsupported ffn_type: {self.ffn_type}") | |
| if self.parametrization != "standard": | |
| raise ValueError(f"unsupported parametrization: {self.parametrization}") | |
| def from_preset(cls, name: str, **overrides) -> "MyModelConfig": | |
| if name not in PRESETS: | |
| raise ValueError(f"unknown preset {name!r}; choose from {sorted(PRESETS)}") | |
| values = dict(PRESETS[name]) | |
| values.update(overrides) | |
| return cls(**values) | |
| def estimate_parameters(self) -> int: | |
| """Formula-based parameter count, excluding q/k norm parameters.""" | |
| d = self.hidden_size | |
| attn = 2 * d * (self.num_attention_heads * self.head_dim) | |
| attn += 2 * d * (self.num_key_value_heads * self.head_dim) | |
| ffn = 3 * d * self.intermediate_size | |
| norms = self.num_hidden_layers * 2 * d + d | |
| if self.qk_norm: | |
| norms += self.num_hidden_layers * 2 * self.head_dim | |
| embedding = self.vocab_size * d | |
| return self.num_hidden_layers * (attn + ffn) + norms + embedding | |