Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "MoxStone/SmaliLLM-Qwen3-0.6B-Finetuned"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8model_name,
9torch_dtype="auto",
10device_map="auto"
11)
12
13# prepare the model input
14prompt = "Smali Code You Want to Decompile"
15messages = [
16{"role":"system", "content": "Decompile following smali code to java code."}
17{"role": "user", "content": prompt}
18]
19text = tokenizer.apply_chat_template(
20messages,
21tokenize=False,
22add_generation_prompt=True,
23enable_thinking=False # In the Qwen3 base model, we use the non-thinking mode to decompile Smali code.
24)
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27# conduct text completion
28generated_ids = model.generate(
29**model_inputs,
30max_new_tokens=8192
31)
32output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
33
34# parsing thinking content
35try:
36# rindex finding 151668 (</think>)
37index = len(output_ids) - output_ids[::-1].index(151668)
38except ValueError:
39index = 0
40
41thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
42content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
43
44print("Java code:", content)