Instructions to use tencent/Youtu-LLM-2B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/Youtu-LLM-2B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tencent/Youtu-LLM-2B-Base")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tencent/Youtu-LLM-2B-Base") model = AutoModelForCausalLM.from_pretrained("tencent/Youtu-LLM-2B-Base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tencent/Youtu-LLM-2B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tencent/Youtu-LLM-2B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tencent/Youtu-LLM-2B-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tencent/Youtu-LLM-2B-Base
- SGLang
How to use tencent/Youtu-LLM-2B-Base 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 "tencent/Youtu-LLM-2B-Base" \ --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": "tencent/Youtu-LLM-2B-Base", "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 "tencent/Youtu-LLM-2B-Base" \ --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": "tencent/Youtu-LLM-2B-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tencent/Youtu-LLM-2B-Base with Docker Model Runner:
docker model run hf.co/tencent/Youtu-LLM-2B-Base
remove redundant function
#7
by Junrulu - opened
- modeling_youtu.py +0 -24
modeling_youtu.py
CHANGED
|
@@ -414,30 +414,6 @@ class YoutuPreTrainedModel(PreTrainedModel):
|
|
| 414 |
"attentions": YoutuMLAttention,
|
| 415 |
}
|
| 416 |
|
| 417 |
-
def init_weights(self):
|
| 418 |
-
"""
|
| 419 |
-
If needed prunes and maybe initializes weights. If using a custom `PreTrainedModel`, you need to implement any
|
| 420 |
-
initialization logic in `_init_weights`.
|
| 421 |
-
"""
|
| 422 |
-
# Prune heads if needed
|
| 423 |
-
if self.config.pruned_heads:
|
| 424 |
-
self.prune_heads(self.config.pruned_heads)
|
| 425 |
-
|
| 426 |
-
if "-init" in self.name_or_path:
|
| 427 |
-
# Initialize weights
|
| 428 |
-
self.apply(self._initialize_weights)
|
| 429 |
-
|
| 430 |
-
# Adjust weights of o_proj in Attention and down_proj in MLP
|
| 431 |
-
for name, module in self.named_modules():
|
| 432 |
-
if "o_proj" in name or "down_proj" in name:
|
| 433 |
-
# For the output projection, we reinitialize the weights
|
| 434 |
-
scaled_std = self.config.initializer_range * (1.0 / self.config.num_hidden_layers) ** 0.5
|
| 435 |
-
module.weight.data.normal_(mean=0.0, std=scaled_std)
|
| 436 |
-
|
| 437 |
-
# Tie weights should be skipped when not initializing all weights
|
| 438 |
-
# since from_pretrained(...) calls tie weights anyways
|
| 439 |
-
self.tie_weights()
|
| 440 |
-
|
| 441 |
def _init_weights(self, module):
|
| 442 |
super()._init_weights(module)
|
| 443 |
std = self.config.initializer_range
|
|
|
|
| 414 |
"attentions": YoutuMLAttention,
|
| 415 |
}
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
def _init_weights(self, module):
|
| 418 |
super()._init_weights(module)
|
| 419 |
std = self.config.initializer_range
|