Instructions to use AutomatedScientist/pynb-73m-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AutomatedScientist/pynb-73m-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AutomatedScientist/pynb-73m-base")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AutomatedScientist/pynb-73m-base", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AutomatedScientist/pynb-73m-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AutomatedScientist/pynb-73m-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AutomatedScientist/pynb-73m-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AutomatedScientist/pynb-73m-base
- SGLang
How to use AutomatedScientist/pynb-73m-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 "AutomatedScientist/pynb-73m-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": "AutomatedScientist/pynb-73m-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 "AutomatedScientist/pynb-73m-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": "AutomatedScientist/pynb-73m-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AutomatedScientist/pynb-73m-base with Docker Model Runner:
docker model run hf.co/AutomatedScientist/pynb-73m-base
| """inference.py - Code generation model wrapper for smolagents""" | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| class CodeModel: | |
| def __init__(self, model_id: str, device: str = None): | |
| self.device = device or ("cuda" if torch.cuda.is_available() else "cpu") | |
| self.tokenizer = AutoTokenizer.from_pretrained(model_id, fix_mistral_regex=True) | |
| dtype = torch.bfloat16 if self.device == "cuda" else torch.float32 | |
| self.model = AutoModelForCausalLM.from_pretrained(model_id).to(self.device, dtype=dtype) | |
| self.model.eval() | |
| def generate(self, prompt: str, max_new_tokens: int = 512, temperature: float = 0.7) -> str: | |
| inputs = self.tokenizer(prompt, return_tensors="pt").to(self.device) | |
| with torch.no_grad(): | |
| outputs = self.model.generate( | |
| **inputs, | |
| max_new_tokens=max_new_tokens, | |
| temperature=temperature, | |
| do_sample=True, | |
| top_p=0.9, | |
| repetition_penalty=1.2, | |
| pad_token_id=self.tokenizer.pad_token_id, | |
| eos_token_id=self.tokenizer.eos_token_id, | |
| ) | |
| new_tokens = outputs[0, inputs["input_ids"].shape[1]:] | |
| return self.tokenizer.decode(new_tokens, skip_special_tokens=False) | |
| def chat(self, messages: list[dict], max_new_tokens: int = 256) -> str: | |
| """Generate response using chat template.""" | |
| text = self.tokenizer.apply_chat_template( | |
| messages, | |
| add_generation_prompt=True, | |
| tokenize=False | |
| ) | |
| inputs = self.tokenizer(text, return_tensors="pt").to(self.device) | |
| with torch.no_grad(): | |
| outputs = self.model.generate( | |
| **inputs, | |
| max_new_tokens=max_new_tokens, | |
| do_sample=True, | |
| temperature=0.7, | |
| top_p=0.9, | |
| repetition_penalty=1.2, | |
| ) | |
| new_tokens = outputs[0, inputs["input_ids"].shape[1]:] | |
| return self.tokenizer.decode(new_tokens, skip_special_tokens=False) | |
| if __name__ == "__main__": | |
| import os | |
| # Use local checkpoint if available, otherwise HuggingFace | |
| model_id = "checkpoint" if os.path.exists("checkpoint") else "AutomatedScientist/pynb-73m-base" | |
| model = CodeModel(model_id) | |
| # Example: Generate code | |
| result = model.generate("Write a Python function to calculate factorial") | |
| print("Generated code:") | |
| print(result) | |
| # Example: Chat | |
| messages = [ | |
| {"role": "system", "content": "You are a helpful coding assistant."}, | |
| {"role": "user", "content": "Write a function to reverse a string"} | |
| ] | |
| response = model.chat(messages) | |
| print("\nChat response:") | |
| print(response) | |