allenai/c4
Viewer • Updated • 10.4B • 837k • 591
How to use Qwest/Space_Oleg with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Qwest/Space_Oleg", trust_remote_code=True) # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("Qwest/Space_Oleg", trust_remote_code=True, dtype="auto")How to use Qwest/Space_Oleg with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Qwest/Space_Oleg"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Qwest/Space_Oleg",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/Qwest/Space_Oleg
How to use Qwest/Space_Oleg with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Qwest/Space_Oleg" \
--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": "Qwest/Space_Oleg",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "Qwest/Space_Oleg" \
--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": "Qwest/Space_Oleg",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use Qwest/Space_Oleg with Docker Model Runner:
docker model run hf.co/Qwest/Space_Oleg
CosmoFormer — это каузальная языковая модель (causal LM) с архитектурой на основе Grouped Query Attention (GQA), SwiGLU FFN и синусоидальных позиционных кодирований.
| Компонент | Описание |
|---|---|
| Embedding | Стандартный слой nn.Embedding с масштабированием √d_model |
| Positional Encoding | Синусоидальные кодирования (Sinusoidal) |
| Attention | Grouped Query Attention (GQA) – ускорение инференса за счёт группировки KV-heads |
| FFN | Два линейных слоя с активацией SiLU (SwiGLU-подобный) |
| Голова | lm_head (без bias) для генерации токенов |
Все параметры конфигурации задаются в config.json.
Модель использует GPT2‑токенизатор из библиотеки transformers. Установите зависимости:
pip install torch transformers safetensors huggingface_hub
from transformers import AutoModelForCausalLM, GPT2Tokenizer
model = AutoModelForCausalLM.from_pretrained("Qwest/Space_Oleg", trust_remote_code=True)
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
tokenizer.pad_token = tokenizer.eos_token
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device).eval()
prompt = "python is a "
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
with torch.no_grad():
output_ids = model.generate(
input_ids,
max_length=100,
temperature=0.8,
top_k=50,
top_p=0.95,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
generated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
print(generated_text)
По умолчанию в репозитории используется конфигурация:
| Параметр | Значение |
|---|---|
| d_model | 512 |
| d_ff | 1024 |
| num_layers | 12 |
| num_heads | 8 |
| num_groups | 2 |
| vocab_size | 50257 |
| max_len | 2048 |
Архитектура вдохновлена современными подходами (GQA из LLaMA, SwiGLU из PaLM). Код написан с нуля под задачи автора.