w
gcw_uQ09W7jl/hmellor-tiny-random-LlamaForCausalLM-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

hmellor/tiny-random-LlamaForCausalLM - Ascend NPU

tiny-random LlamaForCausalLM (2 layers, hidden 16, vocab 32000) adapted for Huawei Ascend 910B NPU.

Model Info

  • Architecture: LlamaForCausalLM (llama)
  • Params: ~0.5M (tiny-random for testing)
  • Task: text-generation (Causal LM, greedy decoding)
  • Original: https://huggingface.co/hmellor/tiny-random-LlamaForCausalLM

NPU Adaptation

  • Device: npu:0 (Ascend910_9362)
  • dtype: float32 (torch.float32)
  • Verified: next(model.parameters()).device == npu:0, input_ids.device == npu:0, logits.device == npu:0, generated.device == npu:0
  • Greedy decoding: token ids CPU vs NPU exactly match (seed 42)

Usage

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch, torch_npu

model_id = "hmellor/tiny-random-LlamaForCausalLM"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.float32).to("npu:0").eval()

inputs = tokenizer(["Hello, my dog is cute"], return_tensors="pt").to("npu:0")
out = model.generate(**inputs, max_new_tokens=20, do_sample=False)
print(tokenizer.decode(out[0], skip_special_tokens=True))

Or run bundled inference:

pip install -r requirements.txt
python inference.py

Validation

  • NPU: Ascend910_9362, device_count=2, free ~61 GiB
  • Input prompts: "Hello, my dog is cute", "The weather today is beautiful and"
  • Consistency: greedy token ids identical CPU vs NPU; logits max diff 0.23 (fp32, prompt1) within tolerance, prompt0 0.0
  • Performance: first compile ~0.22s, stable ~0.12s, ~332 tokens/s (new tokens)

Evidence

agent workflow npu device call model result