Instructions to use facebook/MobileLLM-350M-layer-share with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/MobileLLM-350M-layer-share with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="facebook/MobileLLM-350M-layer-share", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("facebook/MobileLLM-350M-layer-share", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use facebook/MobileLLM-350M-layer-share with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "facebook/MobileLLM-350M-layer-share" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "facebook/MobileLLM-350M-layer-share", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/facebook/MobileLLM-350M-layer-share
- SGLang
How to use facebook/MobileLLM-350M-layer-share 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 "facebook/MobileLLM-350M-layer-share" \ --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": "facebook/MobileLLM-350M-layer-share", "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 "facebook/MobileLLM-350M-layer-share" \ --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": "facebook/MobileLLM-350M-layer-share", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use facebook/MobileLLM-350M-layer-share with Docker Model Runner:
docker model run hf.co/facebook/MobileLLM-350M-layer-share
MobileLLM-350M-LS: Unused and Uninitialized Weights, Repeated Output During Generation
Description
When using MobileLLM-350M-LS with transformers library, I encountered the following issues:
Warnings:
- Unused weights:
lm_head.weight. - Reinitialized weights:
model.embed_tokens.weight.
- Unused weights:
Output Issues:
- Generated text contains excessive repetition. For example:
Hello! Who are you? Below are some of the questions we ask new members. What is your name? What is your birthday? What is your birthday? ...
- Generated text contains excessive repetition. For example:
Environment
- Transformers version: 4.44.0
- Python version: 3.11
Code
from transformers import AutoTokenizer, AutoModelForCausalLM
def infer_mobilellm():
model_dir = "/nfs/300-MT-Pro/model/huggingface/MobileLLM-350M-LS"
tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True)
input_text = "Hello! Who are you?"
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_length=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
infer_mobilellm()
Questions
What is the correct way to initialize and perform inference with MobileLLM-350M-LS?
Hi, thank you for raising this issue! The lm_head.weight is the same as model.embed_tokens.weight, so loading either of them should be fine.
The model is a pre-trained model, not a chat-finetuned model. Therefore, it can only complete sentences, not answer questions. Does that make sense?
For repeated sentences, you can try setting repetition_penalty=1.5; this will help avoid generating repeated outputs.