Text Generation
Transformers
Safetensors
German
English
llama
causal-lm
base-model
pretrained
from-scratch
german
english
bilingual
small-language-model
text-generation-inference
Instructions to use Evicka/Hanse2-100M-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Evicka/Hanse2-100M-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Evicka/Hanse2-100M-Base")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Evicka/Hanse2-100M-Base") model = AutoModelForCausalLM.from_pretrained("Evicka/Hanse2-100M-Base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Evicka/Hanse2-100M-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Evicka/Hanse2-100M-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Evicka/Hanse2-100M-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Evicka/Hanse2-100M-Base
- SGLang
How to use Evicka/Hanse2-100M-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 "Evicka/Hanse2-100M-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": "Evicka/Hanse2-100M-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 "Evicka/Hanse2-100M-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": "Evicka/Hanse2-100M-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Evicka/Hanse2-100M-Base with Docker Model Runner:
docker model run hf.co/Evicka/Hanse2-100M-Base
Download train_tokenizer.py from Evicka/Hanse2-100M-Base: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/Evicka/Hanse2-100M-Base/resolve/main/train_tokenizer.py
- Command line
-
hf download hf://Evicka/Hanse2-100M-Base/train_tokenizer.py
-
curl -L -o train_tokenizer.py https://huggingface.co/Evicka/Hanse2-100M-Base/resolve/main/train_tokenizer.py
2.17 kB
| from pathlib import Path | |
| from datasets import interleave_datasets, load_dataset | |
| from tokenizers import ByteLevelBPETokenizer | |
| from tqdm import tqdm | |
| NUM_DOCUMENTS = 500_000 | |
| VOCAB_SIZE = 32_000 | |
| SEED = 42 | |
| OUTPUT_FILE = Path(__file__).with_name("hanse_tokenizer.json") | |
| SOURCES = ( | |
| ("HuggingFaceFW/fineweb-edu", "sample-10BT", 0.40), | |
| ("HuggingFaceFW/fineweb-2", "deu_Latn", 0.35), | |
| ("HuggingFaceFW/finewiki", "de", 0.20), | |
| ("HuggingFaceFW/finewiki", "en", 0.05), | |
| ) | |
| SPECIAL_TOKENS = ( | |
| "<|pad|>", | |
| "<|bos|>", | |
| "<|eos|>", | |
| "<|unk|>", | |
| "<|system|>", | |
| "<|user|>", | |
| "<|assistant|>", | |
| "<|tool|>", | |
| "<|tool_result|>", | |
| "<|end_of_turn|>", | |
| ) | |
| def training_corpus(dataset): | |
| accepted = 0 | |
| with tqdm(total=NUM_DOCUMENTS, desc="Feeding documents", unit="docs", dynamic_ncols=True) as progress: | |
| for example in dataset: | |
| text = example.get("text") | |
| if not isinstance(text, str) or not (text := text.strip()): | |
| continue | |
| yield text | |
| accepted += 1 | |
| progress.update() | |
| if accepted == NUM_DOCUMENTS: | |
| return | |
| raise RuntimeError(f"Dataset exhausted after {accepted:,} usable documents") | |
| def main() -> None: | |
| streams = [ | |
| load_dataset(name, config, split="train", streaming=True) | |
| for name, config, _ in SOURCES | |
| ] | |
| dataset = interleave_datasets( | |
| streams, | |
| probabilities=[probability for _, _, probability in SOURCES], | |
| seed=SEED, | |
| stopping_strategy="all_exhausted", | |
| ) | |
| tokenizer = ByteLevelBPETokenizer() | |
| tokenizer.train_from_iterator( | |
| training_corpus(dataset), | |
| vocab_size=VOCAB_SIZE, | |
| min_frequency=2, | |
| special_tokens=list(SPECIAL_TOKENS), | |
| length=NUM_DOCUMENTS, | |
| show_progress=True, | |
| ) | |
| assert tokenizer.get_vocab_size() == VOCAB_SIZE | |
| assert [tokenizer.token_to_id(token) for token in SPECIAL_TOKENS] == list(range(len(SPECIAL_TOKENS))) | |
| tokenizer.save(str(OUTPUT_FILE)) | |
| print(f"[+] Saved {tokenizer.get_vocab_size():,}-token tokenizer to {OUTPUT_FILE}") | |
| if __name__ == "__main__": | |
| main() | |