Text Generation
Transformers
Safetensors
PyTorch
English
Portuguese
kern_qwen3_moe
kern
sparse-moe
experimental
custom_code
conversational
Instructions to use Project-KERN/KERN-Lab-0.5-624M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Project-KERN/KERN-Lab-0.5-624M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Project-KERN/KERN-Lab-0.5-624M", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Project-KERN/KERN-Lab-0.5-624M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Project-KERN/KERN-Lab-0.5-624M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Project-KERN/KERN-Lab-0.5-624M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Project-KERN/KERN-Lab-0.5-624M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Project-KERN/KERN-Lab-0.5-624M
- SGLang
How to use Project-KERN/KERN-Lab-0.5-624M 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 "Project-KERN/KERN-Lab-0.5-624M" \ --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": "Project-KERN/KERN-Lab-0.5-624M", "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 "Project-KERN/KERN-Lab-0.5-624M" \ --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": "Project-KERN/KERN-Lab-0.5-624M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Project-KERN/KERN-Lab-0.5-624M with Docker Model Runner:
docker model run hf.co/Project-KERN/KERN-Lab-0.5-624M
Download app.py from Project-KERN/KERN-Lab-0.5-624M: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/Project-KERN/KERN-Lab-0.5-624M/resolve/main/app.py
- Command line
-
hf download hf://Project-KERN/KERN-Lab-0.5-624M/app.py
-
curl -L -o app.py https://huggingface.co/Project-KERN/KERN-Lab-0.5-624M/resolve/main/app.py
2.64 kB
| """Optional localhost-only Gradio interface for text continuation.""" | |
| import argparse | |
| from pathlib import Path | |
| import torch | |
| from transformers import AutoTokenizer | |
| from modeling_kern_qwen06b_v1 import load_kern_qwen06b_v1 | |
| def build_interface(model_dir: Path, device: str): | |
| import gradio as gr | |
| dtype = torch.bfloat16 if device == "cuda" and torch.cuda.is_bf16_supported() else torch.float32 | |
| model, _ = load_kern_qwen06b_v1(model_dir, device=device, dtype=dtype) | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| model_dir, config=model.config, local_files_only=True, trust_remote_code=False | |
| ) | |
| def continue_text(prompt: str, max_new_tokens: int) -> str: | |
| if not prompt.strip(): | |
| raise gr.Error("Enter a text prefix to continue.") | |
| inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(model.device) | |
| prompt_tokens = inputs["input_ids"].shape[-1] | |
| if prompt_tokens + int(max_new_tokens) > model.config.max_position_embeddings: | |
| raise gr.Error("The prompt and requested continuation exceed the configured context.") | |
| with torch.inference_mode(): | |
| output = model.generate( | |
| **inputs, | |
| max_new_tokens=int(max_new_tokens), | |
| do_sample=False, | |
| use_cache=True, | |
| pad_token_id=tokenizer.pad_token_id, | |
| ) | |
| return tokenizer.decode(output[0, prompt_tokens:], skip_special_tokens=True) | |
| return gr.Interface( | |
| fn=continue_text, | |
| inputs=[ | |
| gr.Textbox(label="Text to continue", lines=4, value="A group of researchers discovered"), | |
| gr.Slider(1, 256, value=48, step=1, label="New tokens"), | |
| ], | |
| outputs=gr.Textbox(label="Continuation", lines=6), | |
| title="KERN-Lab-0.5-624M", | |
| description=( | |
| "Experimental base model for text continuation. Runs locally. " | |
| "[Official model card](https://huggingface.co/Project-KERN/KERN-Lab-0.5-624M)." | |
| ), | |
| api_name="generate", | |
| analytics_enabled=False, | |
| ) | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--model-dir", type=Path, default=Path(__file__).resolve().parent) | |
| parser.add_argument("--device", choices=("auto", "cpu", "cuda"), default="auto") | |
| options = parser.parse_args() | |
| device = options.device | |
| if device == "auto": | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| build_interface(options.model_dir, device).launch(server_name="127.0.0.1", share=False) | |
| if __name__ == "__main__": | |
| main() | |