from peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer from finqa_ft.data import Example # pip install git+https://github.com/Tanatas298/finqa-lorafrom finqa_ft.program import executefrom finqa_ft.prompts import extract_program, messages, render tok = AutoTokenizer.from_pretrained("Qwen/Qwen3-4B")model = AutoModelForCausalLM.from_pretrained( "Qwen/Qwen3-4B", torch_dtype="bfloat16", device_map="auto")model = PeftModel.from_pretrained(model, "Tanatas298/qwen3-4b-finqa-lora") table = [["", "2015", "2014"], ["net earnings from continuing operations", "3538", "3480"]]ex = Example( "demo", "demo", "what was the percentage change in net earnings from 2014 to 2015?", [], [], table, "", "", {},)inputs = tok(render(tok, messages(ex)), return_tensors="pt").to(model.device)out = model.generate(**inputs, max_new_tokens=256, do_sample=False)program = extract_program(tok.decode(out[0][inputs.input_ids.shape[1] :], skip_special_tokens=True))print(program, "=", execute(program, table)) # subtract(3538, 3480), divide(#0, 3480) = 0.01666...