Instructions to use sapbot/toyllama-50m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sapbot/toyllama-50m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sapbot/toyllama-50m")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sapbot/toyllama-50m") model = AutoModelForCausalLM.from_pretrained("sapbot/toyllama-50m") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sapbot/toyllama-50m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sapbot/toyllama-50m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sapbot/toyllama-50m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/sapbot/toyllama-50m
- SGLang
How to use sapbot/toyllama-50m 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 "sapbot/toyllama-50m" \ --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": "sapbot/toyllama-50m", "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 "sapbot/toyllama-50m" \ --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": "sapbot/toyllama-50m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use sapbot/toyllama-50m with Docker Model Runner:
docker model run hf.co/sapbot/toyllama-50m
| import torch | |
| from transformers import AutoTokenizer, LlamaForCausalLM | |
| MODEL_DIR = "sapbot/toyllama-50m" | |
| # --- Generation Settings --- | |
| MAX_NEW_TOKENS = 150 | |
| TEMPERATURE = 0.7 | |
| TOP_P = 0.9 | |
| def main(): | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| print(f"Running inference on: {device.upper()}") | |
| try: | |
| print(f"Loading model from {MODEL_DIR}...") | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR) | |
| model = LlamaForCausalLM.from_pretrained(MODEL_DIR) | |
| model.to(device) | |
| model.eval() | |
| print("Model loaded successfully!\n") | |
| except Exception as e: | |
| print(f"Failed to load. Error: {e}") | |
| return | |
| print("=" * 60) | |
| print("INTERACTIVE MODE: Ready! (Type 'quit' or 'exit' to stop)") | |
| print("=" * 60) | |
| while True: | |
| try: | |
| prompt = input("\n>>> Enter prompt: ") | |
| except (KeyboardInterrupt, EOFError): | |
| print("\nExiting...") | |
| break | |
| if prompt.strip().lower() in ["quit", "exit"]: | |
| print("Goodbye!") | |
| break | |
| if not prompt.strip(): | |
| continue | |
| inputs = tokenizer(prompt, return_tensors="pt").to(device) | |
| inputs.pop("token_type_ids", None) | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=MAX_NEW_TOKENS, | |
| temperature=TEMPERATURE, | |
| top_p=TOP_P, | |
| do_sample=True, | |
| pad_token_id=tokenizer.pad_token_id if tokenizer.pad_token_id is not None else tokenizer.eos_token_id | |
| ) | |
| # GPT-2 Tokenizer handles decoding perfectly out of the box! | |
| generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| print("-" * 60) | |
| print(generated_text.strip()) | |
| print("-" * 60) | |
| if __name__ == "__main__": | |
| main() | |