Instructions to use facebook/MobileLLM-125M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/MobileLLM-125M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="facebook/MobileLLM-125M", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("facebook/MobileLLM-125M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use facebook/MobileLLM-125M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "facebook/MobileLLM-125M" # 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-125M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/facebook/MobileLLM-125M
- SGLang
How to use facebook/MobileLLM-125M 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-125M" \ --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-125M", "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-125M" \ --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-125M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use facebook/MobileLLM-125M with Docker Model Runner:
docker model run hf.co/facebook/MobileLLM-125M
Error running with most recent version of transformers
#9
by Minus0 - opened
Hello! Running this with the current version of Transformers gives me the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-5a5008a62dec> in <cell line: 0>()
1 model_inputs = tokenizer(["A list of colors: red, blue"], return_tensors="pt")
----> 2 generated_ids = model.generate(**model_inputs)
3 tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
3 frames
~/.cache/huggingface/modules/transformers_modules/facebook/MobileLLM-125M/e09efb976ae4a767cf27a4bf277b7aade91dbd3a/modeling_mobilellm.py in prepare_inputs_for_generation(self, input_ids, past_key_values, attention_mask, inputs_embeds, cache_position, use_cache, **kwargs)
1277 max_cache_length = (
1278 torch.tensor(past_key_values.get_max_length(), device=input_ids.device)
-> 1279 if past_key_values.get_max_length() is not None
1280 else None
1281 )
AttributeError: 'DynamicCache' object has no attribute 'get_max_length'
It seems like get_max_length was removed in the latest version of transformers and replaced with cache.get_max_cache_shape() instead.