Run this model with HF Jobs

Run Maaac/CodeLLaMA-Linux-BugFix on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Mac Huang
Push full project including dataset, code, and training scripts
ed6b901
Raw History Blame
2.71 kB
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from datasets import load_dataset
from tqdm import tqdm
import json
import csv
import os
import evaluate
# ==== CONFIG ====
MODEL_PATH = "../train/output/qlora-codellama-bugfix"
EVAL_FILE = "eval.jsonl"
OUTPUT_JSON = "./output/eval_results.json"
OUTPUT_CSV = "./output/eval_results.csv"
MAX_INPUT_LEN = 1024
MAX_NEW_TOKENS = 256
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
# ==== Ensure output folder exists ====
os.makedirs(os.path.dirname(OUTPUT_JSON), exist_ok=True)
# ==== Load model ====
print("πŸ”„ Loading model...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
torch_dtype=torch.bfloat16,
device_map="auto"
)
model.eval()
# ==== Load eval data ====
print("πŸ“‚ Loading evaluation data...")
eval_data = load_dataset("json", data_files=EVAL_FILE, split="train")
# ==== Inference ====
results = []
print("βš™οΈ Running inference...")
for example in tqdm(eval_data):
prompt = example["prompt"]
reference = example["completion"]
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=MAX_INPUT_LEN).to(DEVICE)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=MAX_NEW_TOKENS,
do_sample=False,
num_beams=4,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id
)
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
results.append({
"prompt": prompt,
"reference": reference.strip(),
"prediction": prediction.strip()
})
# ==== Save results ====
with open(OUTPUT_JSON, "w", encoding="utf-8") as f:
json.dump(results, f, indent=2)
print(f"βœ… Saved JSON to {OUTPUT_JSON}")
with open(OUTPUT_CSV, "w", encoding="utf-8", newline='') as f:
writer = csv.DictWriter(f, fieldnames=["prompt", "reference", "prediction"])
writer.writeheader()
writer.writerows(results)
print(f"βœ… Saved CSV to {OUTPUT_CSV}")
# ==== Compute Metrics ====
print("πŸ“Š Computing BLEU and ROUGE...")
bleu = evaluate.load("bleu")
rouge = evaluate.load("rouge")
predictions = [r["prediction"] for r in results]
references = [r["reference"] for r in results]
bleu_score = bleu.compute(predictions=predictions, references=[[ref] for ref in references])
rouge_score = rouge.compute(predictions=predictions, references=references)
print("\nπŸ“ˆ Evaluation Results:")
print("BLEU:", bleu_score)
print("ROUGE:", json.dumps(rouge_score, indent=2))