Text Generation
Transformers
Safetensors
PyTorch
English
logos
causal-lm
custom-code
base-model
custom_code
Instructions to use Rorical/logos-1b-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Rorical/logos-1b-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Rorical/logos-1b-base", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Rorical/logos-1b-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Rorical/logos-1b-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Rorical/logos-1b-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Rorical/logos-1b-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Rorical/logos-1b-base
- SGLang
How to use Rorical/logos-1b-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 "Rorical/logos-1b-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": "Rorical/logos-1b-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 "Rorical/logos-1b-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": "Rorical/logos-1b-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Rorical/logos-1b-base with Docker Model Runner:
docker model run hf.co/Rorical/logos-1b-base
Adapt generate for text-generation pipeline
Browse files- modeling_logos.py +32 -1
modeling_logos.py
CHANGED
|
@@ -2,12 +2,13 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 5 |
import importlib
|
| 6 |
from typing import Any, Dict, Optional
|
| 7 |
|
| 8 |
import torch
|
| 9 |
from torch import nn
|
| 10 |
-
from transformers import PreTrainedModel
|
| 11 |
try:
|
| 12 |
from transformers.generation import GenerationMixin
|
| 13 |
except Exception: # pragma: no cover - older/newer transformers layout guard
|
|
@@ -31,6 +32,18 @@ except ImportError:
|
|
| 31 |
LogosTransformer = importlib.import_module("models.logos").LogosTransformer
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def _reorder_cache_value(value: Any, beam_idx: torch.LongTensor) -> Any:
|
| 35 |
if isinstance(value, torch.Tensor):
|
| 36 |
if value.dim() > 0 and value.size(0) == beam_idx.size(0):
|
|
@@ -95,6 +108,24 @@ class LogosForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 95 |
self.model.lm_head.weight = self.model.token_emb.weight
|
| 96 |
self._reset_rotary_buffers()
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
def _reset_rotary_buffers(self) -> None:
|
| 99 |
for module in self.modules():
|
| 100 |
if module.__class__.__name__ != "RotaryEmbedding":
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
from copy import deepcopy
|
| 6 |
import importlib
|
| 7 |
from typing import Any, Dict, Optional
|
| 8 |
|
| 9 |
import torch
|
| 10 |
from torch import nn
|
| 11 |
+
from transformers import GenerationConfig, PreTrainedModel
|
| 12 |
try:
|
| 13 |
from transformers.generation import GenerationMixin
|
| 14 |
except Exception: # pragma: no cover - older/newer transformers layout guard
|
|
|
|
| 32 |
LogosTransformer = importlib.import_module("models.logos").LogosTransformer
|
| 33 |
|
| 34 |
|
| 35 |
+
_GENERATION_CONFIG_KEYS = set(GenerationConfig().to_dict())
|
| 36 |
+
_SAMPLING_ONLY_KEYS = (
|
| 37 |
+
"temperature",
|
| 38 |
+
"top_k",
|
| 39 |
+
"top_p",
|
| 40 |
+
"min_p",
|
| 41 |
+
"typical_p",
|
| 42 |
+
"epsilon_cutoff",
|
| 43 |
+
"eta_cutoff",
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
def _reorder_cache_value(value: Any, beam_idx: torch.LongTensor) -> Any:
|
| 48 |
if isinstance(value, torch.Tensor):
|
| 49 |
if value.dim() > 0 and value.size(0) == beam_idx.size(0):
|
|
|
|
| 108 |
self.model.lm_head.weight = self.model.token_emb.weight
|
| 109 |
self._reset_rotary_buffers()
|
| 110 |
|
| 111 |
+
def generate(self, *args: Any, **kwargs: Any):
|
| 112 |
+
generation_config = kwargs.get("generation_config")
|
| 113 |
+
if generation_config is not None:
|
| 114 |
+
explicit_keys = _GENERATION_CONFIG_KEYS.intersection(kwargs)
|
| 115 |
+
if explicit_keys:
|
| 116 |
+
merged = deepcopy(generation_config)
|
| 117 |
+
for key in sorted(explicit_keys):
|
| 118 |
+
setattr(merged, key, kwargs.pop(key))
|
| 119 |
+
if "max_new_tokens" in explicit_keys and "max_length" not in explicit_keys:
|
| 120 |
+
merged.max_length = None
|
| 121 |
+
if getattr(merged, "do_sample", None) is False:
|
| 122 |
+
for key in _SAMPLING_ONLY_KEYS:
|
| 123 |
+
if key not in explicit_keys and hasattr(merged, key):
|
| 124 |
+
setattr(merged, key, None)
|
| 125 |
+
kwargs["generation_config"] = merged
|
| 126 |
+
|
| 127 |
+
return super().generate(*args, **kwargs)
|
| 128 |
+
|
| 129 |
def _reset_rotary_buffers(self) -> None:
|
| 130 |
for module in self.modules():
|
| 131 |
if module.__class__.__name__ != "RotaryEmbedding":
|