File size: 1,493 Bytes
ad4bac7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
"""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()