Instructions to use Loom-Labs/Apollo-1-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Loom-Labs/Apollo-1-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Loom-Labs/Apollo-1-4B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Loom-Labs/Apollo-1-4B") model = AutoModelForCausalLM.from_pretrained("Loom-Labs/Apollo-1-4B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Loom-Labs/Apollo-1-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Loom-Labs/Apollo-1-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Loom-Labs/Apollo-1-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Loom-Labs/Apollo-1-4B
- SGLang
How to use Loom-Labs/Apollo-1-4B 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 "Loom-Labs/Apollo-1-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Loom-Labs/Apollo-1-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Loom-Labs/Apollo-1-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Loom-Labs/Apollo-1-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use Loom-Labs/Apollo-1-4B with Docker Model Runner:
docker model run hf.co/Loom-Labs/Apollo-1-4B
Aayan Mishra commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -157,14 +157,51 @@ You can easily integrate Nous-V1 4B via the Hugging Face Transformers library or
|
|
| 157 |
### Using Hugging Face Transformers
|
| 158 |
|
| 159 |
```python
|
| 160 |
-
|
| 161 |
-
from transformers import pipeline
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
messages = [
|
| 165 |
-
{"role": "user", "content":
|
| 166 |
]
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
```
|
| 169 |
|
| 170 |
### Deployment Options
|
|
|
|
| 157 |
### Using Hugging Face Transformers
|
| 158 |
|
| 159 |
```python
|
| 160 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 161 |
|
| 162 |
+
model_name = "apexion-ai/Nous-1-4B"
|
| 163 |
+
|
| 164 |
+
# load the tokenizer and the model
|
| 165 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 166 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 167 |
+
model_name,
|
| 168 |
+
torch_dtype="auto",
|
| 169 |
+
device_map="auto"
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
# prepare the model input
|
| 173 |
+
prompt = "Give me a short introduction to large language model."
|
| 174 |
messages = [
|
| 175 |
+
{"role": "user", "content": prompt}
|
| 176 |
]
|
| 177 |
+
text = tokenizer.apply_chat_template(
|
| 178 |
+
messages,
|
| 179 |
+
tokenize=False,
|
| 180 |
+
add_generation_prompt=True,
|
| 181 |
+
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
|
| 182 |
+
)
|
| 183 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 184 |
+
|
| 185 |
+
# conduct text completion
|
| 186 |
+
generated_ids = model.generate(
|
| 187 |
+
**model_inputs,
|
| 188 |
+
max_new_tokens=32768
|
| 189 |
+
)
|
| 190 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 191 |
+
|
| 192 |
+
# parsing thinking content
|
| 193 |
+
try:
|
| 194 |
+
# rindex finding 151668 (</think>)
|
| 195 |
+
index = len(output_ids) - output_ids[::-1].index(151668)
|
| 196 |
+
except ValueError:
|
| 197 |
+
index = 0
|
| 198 |
+
|
| 199 |
+
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
|
| 200 |
+
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
|
| 201 |
+
|
| 202 |
+
print("thinking content:", thinking_content)
|
| 203 |
+
print("content:", content)
|
| 204 |
+
|
| 205 |
```
|
| 206 |
|
| 207 |
### Deployment Options
|