Text Generation
Transformers
Safetensors
English
alpha-er
from-scratch
mixture-of-experts
custom-gpu-stack
research
custom_code
Instructions to use ajaxdavis/alpha-er with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ajaxdavis/alpha-er with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ajaxdavis/alpha-er", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("ajaxdavis/alpha-er", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ajaxdavis/alpha-er with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ajaxdavis/alpha-er" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ajaxdavis/alpha-er", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ajaxdavis/alpha-er
- SGLang
How to use ajaxdavis/alpha-er 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 "ajaxdavis/alpha-er" \ --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": "ajaxdavis/alpha-er", "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 "ajaxdavis/alpha-er" \ --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": "ajaxdavis/alpha-er", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ajaxdavis/alpha-er with Docker Model Runner:
docker model run hf.co/ajaxdavis/alpha-er
File size: 1,464 Bytes
d7562c8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | """Generate text from alpha-er with the PyTorch port.
Pads to block_size and reads the last real position, which the conditional MLP
requires and which is exact: attention is causal, and each token's expert is a
function of its own position.
"""
import sys, os, json, torch
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from modeling_alpha import AlphaErConfig, AlphaErForCausalLM
from tokenization_alpha import AlphaErTokenizer
from safetensors.torch import load_file
hf_dir = sys.argv[1]
prompts = sys.argv[2:] or ["<|user|>Hello!<|assistant|>"]
temp = float(os.environ.get("TEMP", "0.8"))
topk = int(os.environ.get("TOPK", "40"))
ntok = int(os.environ.get("NTOK", "60"))
cfg_d = json.load(open(f"{hf_dir}/config.json"))
cfg = AlphaErConfig(**{k: v for k, v in cfg_d.items()
if k in AlphaErConfig.__init__.__code__.co_varnames})
model = AlphaErForCausalLM(cfg)
model.load_state_dict(load_file(f"{hf_dir}/model.safetensors"), strict=False)
model.eval()
tok = AlphaErTokenizer.from_file(f"{hf_dir}/tokenizer_artifacts.json")
torch.manual_seed(1234)
print(f"alpha-er step {cfg_d.get('trained_step')} temp={temp} top_k={topk}\n")
for p in prompts:
ids = tok.encode(p)
out = model.generate(torch.tensor([ids]), max_new_tokens=ntok,
temperature=temp, top_k=topk)[0].tolist()
print("=" * 72)
print("PROMPT:", p)
print("OUTPUT:", tok.decode(out[len(ids):]).replace("\n", "\\n"))
|