Instructions to use himalaya-ai/himalayagpt-0.5b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use himalaya-ai/himalayagpt-0.5b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="himalaya-ai/himalayagpt-0.5b-it", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("himalaya-ai/himalayagpt-0.5b-it", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("himalaya-ai/himalayagpt-0.5b-it", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use himalaya-ai/himalayagpt-0.5b-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "himalaya-ai/himalayagpt-0.5b-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "himalaya-ai/himalayagpt-0.5b-it", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/himalaya-ai/himalayagpt-0.5b-it
- SGLang
How to use himalaya-ai/himalayagpt-0.5b-it 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 "himalaya-ai/himalayagpt-0.5b-it" \ --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": "himalaya-ai/himalayagpt-0.5b-it", "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 "himalaya-ai/himalayagpt-0.5b-it" \ --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": "himalaya-ai/himalayagpt-0.5b-it", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use himalaya-ai/himalayagpt-0.5b-it with Docker Model Runner:
docker model run hf.co/himalaya-ai/himalayagpt-0.5b-it
Fix .generate() support: add GenerationMixin + generation_config, document KV-cache limitation
Summary
Calling .generate() on this model currently fails immediately with:
AttributeError: 'NanochatForCausalLM' object has no attribute 'generate'
Root cause: NanochatForCausalLM defines prepare_inputs_for_generation
(a strong "this model supports generation" signal to transformers) but
does not inherit from GenerationMixin. As of transformers>=4.50,PreTrainedModel no longer automatically provides .generate() — this is
a breaking change that's been deprecated-warned for a few versions and is
now enforced. Your own trust_remote_code=True loading path already emits
this exact warning every time the model loads, so this isn't a surprise
bug — it's the deprecation landing.
Reproduction
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
repo = "himalaya-ai/himalayagpt-0.5b-it"
tok = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
repo, trust_remote_code=True, torch_dtype=torch.float32, device_map="auto"
)
ids = tok("नेपालको राजधानी ", return_tensors="pt").input_ids.to(model.device)
out = model.generate(ids, max_new_tokens=64)
AttributeError: 'NanochatForCausalLM' object has no attribute 'generate'
```
Fix in this PR
Add
GenerationMixinto the class bases so.generate()exists:
```python
class NanochatForCausalLM(PreTrainedModel, GenerationMixin):
```Set a default
generation_configin__init__, since nothing
currently provides one andgenerate()reads from it immediately
(self.generation_config.max_length, etc.):
```python
self.generation_config = GenerationConfig.from_model_config(config)
```
That's the minimal fix to make .generate() callable at all.
Known limitation this PR does NOT fix (flagging for visibility)
prepare_inputs_for_generation currently always returns the fullinput_ids regardless of past_key_values, and forward() hardcodespast_key_values=None in its return — meaning there is no KV-cache.
Generation will work correctly after this PR, but every new token
reprocesses the entire sequence from scratch (O(n²) instead of O(n)). For
a 0.5B model at short context this is usable but slow; for longer
generations it'll be noticeably worse than a cached implementation.
I'd suggest treating that as a separate, bigger follow-up PR (it requires
threading cache state through NanochatAttention.forward, which doesn't
currently accept or return any cache tensors) rather than blocking this
fix on it. Happy to take a pass at that separately if useful — wanted to
keep this PR small and easy to review/merge.
Also worth noting: forward() accepts an attention_mask parameter but
never uses it — batched/padded generation will silently ignore padding.
Only affects multi-sequence batched calls, not single-prompt generation.
Testing
After this change, confirmed locally:
model.generate(ids, max_new_tokens=64)runs without raising- Output is well-formed token ids, decodes via
tok.decode(...)normally forward()/ loss computation (training path) is untouched — only the
class declaration and__init__changed
LGTM. Verified that the PR fixes direct .generate() support by adding GenerationMixin and a default GenerationConfig, without touching the model forward path, attention logic, rotary code, or weights.