from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
base = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen3.6-27B", torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base, "AlexThunder0/qwen-cobol-27b")
tok = AutoTokenizer.from_pretrained("AlexThunder0/qwen-cobol-27b")
prompt = '''Complete the following COBOL program by implementing the PROCEDURE DIVISION.
The code MUST compile with the open-source GnuCOBOL compiler. Declare every variable
in WORKING-STORAGE, do not use IBM-only intrinsics, end with exactly one END PROGRAM.
Provide the complete, compilable COBOL program inside a single ```cobol code block.
```cobol
<the COBOLEval-style skeleton with a LINKAGE SECTION and a RESULT field>
```'''
msg = tok.apply_chat_template([{"role": "user", "content": prompt}],
tokenize=False, add_generation_prompt=True, enable_thinking=False)
out = model.generate(**tok(msg, return_tensors="pt").to(model.device),
max_new_tokens=2048, do_sample=False)
print(tok.decode(out[0], skip_special_tokens=True))