evenfarther/DeepSeek-R1-Distill-Qwen-14b-chemical-synthesis-PN-adapter
DeepSeek-R1-Distill-Qwen-14B Chemical Synthesis Classifier — LoRA Adapter (Epoch 9)
Model Overview
This repository contains the LoRA adapter for a DeepSeek‑R1‑Distill‑Qwen‑14B model fine‑tuned to classify chemical synthesizability (P = synthesizable, N = unsynthesizable). Training uses QLoRA on an imbalanced P/N dataset; evaluation scores each example with logsumexp(P) − logsumexp(N) at the final token under the SFT‑aligned prompt.
- Task: Binary classification (P vs N)
- Objective: QLoRA with class‑imbalance handling
- Max sequence length (eval): 180 tokens
- Dataset (train):
train_llm_pn.jsonl - Dataset (val):
valid_llm_pn.jsonl - Checkpoint: Epoch 9 (best Balanced Accuracy among evaluated epochs)
The checkpoint includes a chat_template.jinja to ensure prompt formatting matches SFT conditions.
Model Overview
This repository contains the LoRA adapter for the chemical synthesis classifier fine-tuned with focal loss. Training prompts follow the template:
You are a materials science assistant. Given a chemical composition, answer only with 'P' (synthesizable/positive) or 'N' (non-synthesizable/negative)." Correspondingly, each user query was formatted as: "Is the material {composition} likely synthesizable? Answer with P (positive) or N (negative).
Implementation notes for faithful scoring/inference:
- Build inputs via the chat template; drop the final assistant label from dataset inputs and tokenize with an empty assistant turn.
- Use `add_generation_prompt=False` and read logits right after the assistant start (trim the trailing EOS if present).
- Force `attn_implementation="eager"` for stability.
## Validation Metrics (Epoch 4 — Best)
| Metric | Value |
| ------------------- | ---------- |
| TPR (P Recall) | **0.9750** |
| TNR (N Specificity) | 0.9556 |
## How to Load (Transformers + PEFT)
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig from peft import PeftModel
base = "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit" # Base model repo or equivalent local path
bnb = BitsAndBytesConfig( loadin4bit=True, bnb4bitquanttype="nf4", bnb4bitusedouble_quant=True, )
tok = AutoTokenizer.frompretrained(base, usefast=True) tok.paddingside = "right" if tok.padtoken is None: tok.padtoken = tok.eostoken
model = AutoModelForCausalLM.frompretrained( base, quantizationconfig=bnb, devicemap="auto", attnimplementation="eager", ) model = PeftModel.from_pretrained(model, adapter) model.eval()
Training Setup (Summary)
- Base model: Unsloth "DeepSeek‑R1‑Distill‑Qwen‑14B‑bnb‑4bit" (4‑bit NF4)
- Fine‑tuning: QLoRA via PEFT
- Target modules:
q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj - LoRA config:
r=32, alpha=32, dropout=0.0 - Objective: P/U‑only Focal Loss applied to the last P or N token
gamma=2.0,alpha_P=7.5,alpha_N=1.0- Tokenizer: right‑padding;
pad_token = eos_tokenif undefined
Dataset Sources
The training/validation corpus combines multiple public sources and internal curation:
- P/U labelled data from J. Am. Chem. Soc. 2024, 146, 29, 19654-19659 (doi:10.1021/jacs.4c05840)
- High-entropy materials data from Data in Brief 2018, 21, 2664-2678 (doi:10.1016/j.dib.2018.11.111)
- Additional candidates via literature queries and manual screening of high-entropy materials
VRAM & System Requirements
- GPU VRAM: ≥16 GB recommended (4‑bit base + adapter)
- RAM: ≥16 GB recommended for tokenization and batching
- Libraries: transformers, peft, bitsandbytes (evaluation uses transformers loader)
- Set
attn_implementation="eager"to avoid SDPA instability
Limitations & Notes
- The adapter targets chemical synthesizability judgments; generalization outside this domain is not guaranteed.
- For consistent results, use the included
chat_template.jinjaand avoid inserting<think>tokens. - Do not mutate the base model
config.json(e.g., model_type), which can reinitialize weights and corrupt metrics.
