Text Generation
Transformers
Russian
English
gpt2
causal-lm
experimental
trained-from-scratch
spacemodel
undertrained
Instructions to use openmodelai/Galactic-2.5-Mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openmodelai/Galactic-2.5-Mini with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openmodelai/Galactic-2.5-Mini")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("openmodelai/Galactic-2.5-Mini", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openmodelai/Galactic-2.5-Mini with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openmodelai/Galactic-2.5-Mini" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openmodelai/Galactic-2.5-Mini", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openmodelai/Galactic-2.5-Mini
- SGLang
How to use openmodelai/Galactic-2.5-Mini 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 "openmodelai/Galactic-2.5-Mini" \ --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": "openmodelai/Galactic-2.5-Mini", "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 "openmodelai/Galactic-2.5-Mini" \ --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": "openmodelai/Galactic-2.5-Mini", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openmodelai/Galactic-2.5-Mini with Docker Model Runner:
docker model run hf.co/openmodelai/Galactic-2.5-Mini
Download prepare_data.py from openmodelai/Galactic-2.5-Mini: direct link, hf CLI and curl.
- Browser
- Download file 3.91 kB
-
https://huggingface.co/openmodelai/Galactic-2.5-Mini/resolve/main/prepare_data.py
- Command line
-
hf download hf://openmodelai/Galactic-2.5-Mini/prepare_data.py
-
curl -L -o prepare_data.py https://huggingface.co/openmodelai/Galactic-2.5-Mini/resolve/main/prepare_data.py
3.91 kB
| """Fetch five public-domain literary works and train a fresh RU/EN byte BPE. | |
| Source texts are not redistributed. Check copyright in your jurisdiction. | |
| """ | |
| import hashlib | |
| import json | |
| import re | |
| from pathlib import Path | |
| import numpy as np | |
| import requests | |
| from tokenizers import ByteLevelBPETokenizer | |
| from transformers import GPT2TokenizerFast | |
| ROOT = Path(__file__).resolve().parent | |
| CACHE = ROOT / '.cache' | |
| MODEL = ROOT / 'model' | |
| SOURCES = [ | |
| (14741, 'ru', 'Духовные оды', 'Gavriil Derzhavin'), | |
| (16527, 'ru', '1001 задача для умственного счета', 'Sergei Rachinskii'), | |
| (30774, 'ru', 'Московия в представлении иностранцев XVI-XVII в.', 'Pavel Apostol; editor Georgii Lukomskii'), | |
| (11, 'en', "Alice’s Adventures in Wonderland", 'Lewis Carroll'), | |
| (1342, 'en', 'Pride and Prejudice', 'Jane Austen'), | |
| ] | |
| def main(): | |
| CACHE.mkdir(exist_ok=True) | |
| MODEL.mkdir(exist_ok=True) | |
| manifest, texts = [], {'ru': [], 'en': []} | |
| for book, lang, title, author in SOURCES: | |
| url = f'https://www.gutenberg.org/cache/epub/{book}/pg{book}.txt' | |
| local = CACHE / f'pg{book}.txt' | |
| if not local.exists(): | |
| response = requests.get(url, timeout=90) | |
| response.raise_for_status() | |
| local.write_bytes(response.content) | |
| raw = local.read_bytes() | |
| text = raw.decode('utf-8-sig').replace('\r\n', '\n') | |
| start = re.search(r'\*\*\* START OF (?:THE|THIS) PROJECT GUTENBERG EBOOK.*?\*\*\*', text, re.S) | |
| end = re.search(r'\*\*\* END OF (?:THE|THIS) PROJECT GUTENBERG EBOOK', text) | |
| if not start or not end: | |
| raise ValueError(f'Cannot locate Gutenberg boundaries for {book}') | |
| text = text[start.end():end.start()].strip() | |
| if len(text) < 10000: | |
| raise ValueError('Unexpectedly short source') | |
| # Keep the final 5% of each work out of tokenizer and model training. | |
| boundary = text.rfind('\n', 0, int(len(text) * .95)) | |
| train, valid = text[:boundary], text[boundary:] | |
| texts[lang].append((train, valid)) | |
| manifest.append(dict(id=book, language=lang, title=title, author=author, | |
| url=url, catalog_url=f'https://www.gutenberg.org/ebooks/{book}', | |
| raw_sha256=hashlib.sha256(raw).hexdigest(), | |
| train_characters=len(train), validation_characters=len(valid))) | |
| print(f'{lang}: {title}: {len(text):,} chars', flush=True) | |
| training_files = [] | |
| for lang in texts: | |
| p = CACHE / f'train_{lang}.txt' | |
| p.write_text('\n\n'.join(t[0] for t in texts[lang]), encoding='utf-8') | |
| training_files.append(str(p)) | |
| bpe = ByteLevelBPETokenizer(add_prefix_space=False) | |
| bpe.train(files=training_files, vocab_size=23258, min_frequency=1, | |
| special_tokens=['<|endoftext|>', '<|pad|>']) | |
| if bpe.get_vocab_size() != 23258: | |
| raise ValueError(f'Unexpected vocab size: {bpe.get_vocab_size()}') | |
| bpe.save_model(str(MODEL)) | |
| tok = GPT2TokenizerFast(vocab_file=str(MODEL/'vocab.json'), | |
| merges_file=str(MODEL/'merges.txt'), bos_token='<|endoftext|>', | |
| eos_token='<|endoftext|>', unk_token='<|endoftext|>', pad_token='<|pad|>', | |
| model_max_length=512, clean_up_tokenization_spaces=False) | |
| tok.save_pretrained(MODEL) | |
| for lang, docs in texts.items(): | |
| for split, index in [('train', 0), ('valid', 1)]: | |
| ids = [] | |
| for doc in docs: | |
| ids.extend(tok.encode(doc[index], add_special_tokens=False, truncation=False)) | |
| ids.append(tok.eos_token_id) | |
| np.save(CACHE/f'{split}_{lang}.npy', np.array(ids, dtype=np.int32)) | |
| print(f'{split}/{lang}: {len(ids):,} tokens', flush=True) | |
| (ROOT/'data_sources.json').write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding='utf-8') | |
| if __name__ == '__main__': | |
| main() | |