Mango-T30-1.7B / inference_example.py
ComradeRt's picture
Release Mango T30 1.7B PEFT adapter
ad4bac7 verified
Raw History Blame Contribute Delete
1.49 kB
"""Minimal inference with the Mango T30 1.7B LoRA adapter.
Loads the pinned Qwen3-1.7B base model and applies the Mango adapter with
PEFT. This reproduces the language-model component only; it does not
reproduce the Mango T30 orchestration runtime that was officially evaluated.
"""
import os
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
BASE_MODEL = "Qwen/Qwen3-1.7B"
BASE_REVISION = "70d244cc86ccca08cf5af4e1e306ecf908b1ad5e"
# Set MANGO_ADAPTER to a local directory to load a local copy of this repo.
ADAPTER_MODEL = os.environ.get("MANGO_ADAPTER", "ComradeRt/Mango-T30-1.7B")
def main() -> None:
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, revision=BASE_REVISION)
base = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
revision=BASE_REVISION,
device_map="auto",
dtype="auto",
)
model = PeftModel.from_pretrained(base, ADAPTER_MODEL)
model.eval()
messages = [
{"role": "user",
"content": "Solve x^2 - 5x + 6 = 0 and verify the roots."},
]
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=512, do_sample=False)
new_tokens = output[0][inputs["input_ids"].shape[-1]:]
print(tokenizer.decode(new_tokens, skip_special_tokens=True))
if __name__ == "__main__":
main()