DeepSeek-R1-Distill-Qwen-14B Chemical Synthesis Classifier — LoRA Adapter (Epoch 2)
Model Overview
This repository contains the LoRA adapter for a DeepSeek‑R1‑Distill‑Qwen‑14B model fine‑tuned to classify chemical synthesizability (P = synthesizable, U = unsynthesizable). Training uses QLoRA on an imbalanced P/U dataset; evaluation scores each example with logsumexp(P) − logsumexp(U) at the final token under the SFT‑aligned prompt.
- Task: Binary classification (P vs U)
- Objective: QLoRA with class‑imbalance handling
- Max sequence length (eval): 180 tokens
- Dataset (train):
train_pu_hem.jsonl
(316,442 samples) - Dataset (val):
validate_pu_hem.jsonl
(79,114 samples) - Adapter size: ~1.10 GB (
adapter_model.safetensors
) - Checkpoint: Epoch 2 —
checkpoint-496
(best TPR among evaluated epochs)
The checkpoint includes a chat_template.jinja
to ensure prompt formatting matches SFT conditions.
Prompt & Assistant Prefill
Evaluation and recommended usage preserve the SFT formatting and avoid think tokens:
- System:
You are a helpful assistant for P/U classification of synthesizability.
- User: Dataset-provided query. In the training corpus it follows the pattern:
As chief synthesis scientist, judge {composition} critically. Avoid bias. P=synthesizable, U=not:
- Assistant (prefill): empty assistant start; do not insert
<think>
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 2 — Best)
Metric | Value |
---|---|
TPR (P Recall) | 0.9901 |
TNR (U Specificity) | 0.8160 |
Source: sft/deepseek_14b_sft_outputs/validation_metrics.csv
(loader: transformers).
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
adapter = "<this-repo-or-local-checkpoint-dir>" # This adapter (checkpoint-496)
bnb = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
)
tok = AutoTokenizer.from_pretrained(base, use_fast=True)
tok.padding_side = "right"
if tok.pad_token is None:
tok.pad_token = tok.eos_token
model = AutoModelForCausalLM.from_pretrained(
base,
quantization_config=bnb,
device_map="auto",
attn_implementation="eager",
)
model = PeftModel.from_pretrained(model, adapter)
model.eval()
# Build messages using the included chat template
messages = [
{"role": "system", "content": "You are a helpful assistant for P/U classification of synthesizability."},
{"role": "user", "content": "As chief synthesis scientist, judge FeCrNiMn high-entropy alloy critically. Avoid bias. P=synthesizable, U=not:"},
{"role": "assistant", "content": None}, # empty assistant prefill (no <think>)
]
ids = tok.apply_chat_template(messages, tokenize=True, add_generation_prompt=False, return_tensors="pt").to(model.device)
out = model(input_ids=ids, use_cache=False)
logits = out.logits[0, -1]
# Compare logsumexp over token ids for P vs U to obtain the score.
Training Data
- Train split:
train_pu_hem.jsonl
— 316,442 samples- Label distribution: 34,685
P
(10.96%), 281,757U
(89.04%)
- Label distribution: 34,685
- Validation split:
validate_pu_hem.jsonl
— 79,114 samples- Label distribution: 8,674
P
(10.96%), 70,440U
(89.04%)
- Label distribution: 8,674
- Format: JSONL with
messages
= [{role: "user", content: pattern above}, {role: "assistant", content: "P"|"U"}] - Training injects the fixed system message shown above and tokenizes with
add_generation_prompt=False
, appending EOS.
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
- Target modules:
- Objective: P/U‑only Focal Loss applied to the last P or U token
gamma=2.0
,alpha_P=8.12
,alpha_U=1.0
- Tokenizer: right‑padding;
pad_token = eos_token
if undefined - Saving: periodic checkpoints;
checkpoint-496
corresponds to Epoch 2
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
After de-duplication across sources, the validation split contains 79,114 samples with an imbalanced label ratio (~11% P / 89% U).
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.jinja
and avoid inserting<think>
tokens. - Do not mutate the base model
config.json
(e.g., model_type), which can reinitialize weights and corrupt metrics.
- Downloads last month
- 27
Model tree for evenfarther/DeepSeek-R1-Distill-Qwen-14b-chemical-synthesis-adapter-high-TPR
Base model
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B