Views
No views yet
| Base | jonam-ai/gemma-2-2b-legal-sft (continued) |
| Method | QLoRA — 4-bit NF4 base, LoRA r=16, α=32 on q/k/v/o/gate/up/down_proj |
| Trainable params | 20.8M (0.79% of 2.61B) |
| Data | 3,866 RAFT examples: oracle + 2 distractors, P(oracle kept) = 0.8 |
| Loss masking | completion-only |
| Schedule | 2 epochs, lr 2e-4 cosine, effective batch 16 |
| Hardware / cost | 1×A100-40GB on Modal, ~34 min, ~$1.5 |
| Final train loss | ~0.16 |
##begin_quote## … ##end_quote##, then gives the final answer.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4tok = AutoTokenizer.from_pretrained("jonam-ai/gemma-2-2b-legal-raft")
5model = AutoModelForCausalLM.from_pretrained(
6 "jonam-ai/gemma-2-2b-legal-raft", torch_dtype=torch.bfloat16, device_map="auto")
7
8system = ("You are a legal and financial assistant. Use the numbered context documents "
9 "to answer the question. Quote the text you rely on, then give the final answer.")
10context = ("Context:\n"
11 "[1] The Company entered into a five-year lease for its headquarters commencing "
12 "January 1, 2020, at an annual rent of $2.4 million.\n"
13 "[2] The board declared a quarterly dividend of $0.15 per share, payable in March.")
14question = "What is the annual rent for the Company's headquarters lease?"
15
16msgs = [{"role": "user", "content": f"{system}\n\n{context}\n\nQuestion: {question}"}]
17ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to(model.device)
18out = model.generate(ids, max_new_tokens=200, do_sample=True, temperature=0.5)
19print(tok.decode(out[0, ids.shape[1]:], skip_special_tokens=True))
20# -> ...##begin_quote##...annual rent of $2.4 million.##end_quote## Final answer: $2.4 million per year.