Nhoodie commited on
Commit
644a18b
Β·
verified Β·
1 Parent(s): 4e7c014

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +63 -71
README.md CHANGED
@@ -1,123 +1,115 @@
1
  ---
2
- license: mit
3
- base_model: zehui127/Omni-DNA-20M
4
  tags:
5
- - dna
6
- - genomics
7
- - mutation
8
- - horizontal-gene-transfer
9
- - sad
10
- - sequential-attenuation-denoising
 
 
11
  pipeline_tag: text-generation
12
  ---
13
 
14
  # Omni-DNA SAD Mutation Model
15
 
16
- Fine-tuned **Omni-DNA-20M** for cross-domain horizontal gene transfer (HGT) mutation prediction using **SAD (Sequential Attenuation Denoising)**.
17
 
18
  ## Architecture
19
 
20
- - **Base model**: [zehui127/Omni-DNA-20M](https://huggingface.co/zehui127/Omni-DNA-20M) β€” OLMo-based causal LM, 20M parameters
21
- - **Pretraining scope**: Multi-task, cross-taxonomic-domain genomic data (broadest among candidates)
22
- - **Context**: 250 BPE tokens (~500-2000 bp)
23
 
24
  ## SAD Pipeline
25
 
26
  ```
27
- Stage 1 (ICI) Stage 2 (Attenuation)
28
- ───────────────────── ─────────────────────────
29
- Fine-tune on synthetic pairs Fine-tune on real pairs
30
- Omni-DNA-20M (pretrained) β†’ Stage 1 checkpoint β†’ Final model
31
- 8,112 pairs Γ— 10 epochs 3,317 pairs Γ— 5 epochs
32
- lr = 5e-5 lr = 1e-5 (10x lower)
 
 
 
 
33
  ```
34
 
35
- **SAD Coefficient**: **4.89** (81,120 synthetic exposures / 16,585 real exposures)
36
-
37
- ## ICI (Interleaved Codon Interleaving) β€” Synthetic Data Generation
38
 
39
- Synthetic mutation pairs generated via dual-model consensus:
40
- - **FDI codon gap distance: 3** (gap every 3rd codon = 9 bp gap)
41
- - **Model A**: Omni-DNA-20M (BPE causal LM)
42
- - **Model B**: HyenaDNA tiny-1k (single-nucleotide causal LM, 451K params)
43
- - Models generate independently at each gap; agreement = consensus, disagreement = contested
44
- - 8 generation passes, gap intervals {3,4,5,6} Γ— seeds {42,137}, deduplicated
45
- - Consensus rate: 2.0% (98% contested β€” models have fundamentally different representations)
 
46
 
47
  ## Checkpoints
48
 
49
- | Path | Stage | Description |
50
- |------|-------|-------------|
51
- | `stage1_ici/` | Stage 1 | Weights after synthetic pre-training (ICI) |
52
- | `stage2_sad/` | Stage 2 | Weights after real-data attenuation (final) |
53
 
54
- ## Benchmark Results (200 test pairs)
55
 
56
  | Model | Levenshtein ↓ | Similarity ↑ | Mutation Recall ↑ |
57
  |-------|:---:|:---:|:---:|
58
- | **Base Omni (no fine-tuning)** | 359.2 | 44.0% | **74.3%** |
59
  | Stage 1 (synthetic only) | 260.1 | 45.1% | 67.3% |
60
- | **Stage 2 SAD (synthetic→real)** | 268.2 | 43.8% | 67.8% |
61
-
62
- ### Analysis
63
-
64
- - Base Omni has strong zero-shot mutation-sensing (74.3% recall)
65
- - Stage 1 improved Levenshtein distance (359β†’260) but hurt recall (74.3β†’67.3%)
66
- - SAD attenuation barely recovered recall (67.3β†’67.8%)
67
- - **The SAD coefficient of 4.89 is too high** β€” synthetic patterns overwhelm real data correction
68
-
69
- ### Data Distribution Mismatch
70
 
71
- | Dataset | Mean Mutation Rate |
72
- |---------|-------------------|
73
- | Synthetic (ICI) | 17.8% |
74
- | Real (train) | 3.9% |
75
- | Real (test) | 0.8% |
76
 
77
- The 4.5x mutation rate gap between synthetic and real data teaches the model to over-mutate. With a lower SAD coefficient (more real-data epochs), attenuation could correct this.
 
 
78
 
79
  ## Usage
80
 
81
  ```python
82
- from transformers import AutoTokenizer, AutoModelForCausalLM
83
  import torch
 
84
 
85
- # Load Stage 2 (final) model
86
  tokenizer = AutoTokenizer.from_pretrained("Nhoodie/omni-dna-sad-mutation", subfolder="stage2_sad", trust_remote_code=True)
87
- model = AutoModelForCausalLM.from_pretrained("Nhoodie/omni-dna-sad-mutation", subfolder="stage2_sad", trust_remote_code=True)
88
 
89
- # IMPORTANT: Omni's .generate() outputs PAD immediately. Use manual autoregressive:
90
- def predict_child(model, tokenizer, parent, max_new_tokens=200, temperature=0.2):
91
  prompt = f"mutate: {parent} -> "
92
- input_ids = tokenizer(prompt, return_tensors="pt")["input_ids"]
93
  generated = input_ids
94
  suppress = {0, 1, 2, 3} # UNK, CLS, SEP, PAD
 
95
  with torch.inference_mode():
96
  for _ in range(max_new_tokens):
97
  logits = model(input_ids=generated).logits[:, -1, :] / max(temperature, 0.01)
98
- for s in suppress: logits[0, s] = float("-inf")
99
- next_token = torch.softmax(logits, dim=-1).multinomial(1)
 
 
100
  generated = torch.cat([generated, next_token], dim=-1)
 
101
  text = tokenizer.decode(generated[0, input_ids.shape[1]:], skip_special_tokens=True)
102
  return "".join(c for c in text.upper() if c in "ACGT")
103
 
104
- child = predict_child(model, tokenizer, "ATGCGTACGTACGT...")
 
 
105
  ```
106
 
107
  ## Dataset
108
 
109
  Training data available at: [Nhoodie/omni-dna-sad-mutation-dataset](https://huggingface.co/datasets/Nhoodie/omni-dna-sad-mutation-dataset)
110
 
111
- ## Training Details
112
-
113
- - **Hardware**: NVIDIA GTX 1080 8GB
114
- - **Framework**: PyTorch 2.6.0, transformers 4.49.0, ai2-olmo 0.6.0
115
- - **Stage 1**: 10 epochs, lr=5e-5, cosine schedule, batch=16Γ—2, fp32
116
- - **Stage 2**: 5 epochs, lr=1e-5, cosine schedule, batch=16Γ—2, fp32
117
- - **Total training time**: ~90 min (Stage 1) + ~30 min (Stage 2)
118
-
119
- ## Known Issues
120
 
121
- 1. **Omni `.generate()` is broken** β€” model outputs PAD/EOS with very high confidence after fine-tuning. Must use manual autoregressive loop.
122
- 2. **SAD coefficient too high** β€” 4.89 means synthetic patterns dominate. Needs more real-data epochs to attenuate effectively.
123
- 3. **Synthetic mutation rate mismatch** β€” 17.8% synthetic vs 3.9% real creates distribution shift.
 
 
1
  ---
2
+ license: apache-2.0
 
3
  tags:
4
+ - dna
5
+ - genomics
6
+ - mutation-prediction
7
+ - sad
8
+ - omni-dna
9
+ - hyenadna
10
+ - causal-lm
11
+ base_model: zehui127/Omni-DNA-20M
12
  pipeline_tag: text-generation
13
  ---
14
 
15
  # Omni-DNA SAD Mutation Model
16
 
17
+ Fine-tuned Omni-DNA-20M for cross-domain HGT (Horizontal Gene Transfer) mutation prediction using **SAD (Sequential Attenuation Denoising)**.
18
 
19
  ## Architecture
20
 
21
+ - **Base**: [Omni-DNA-20M](https://huggingface.co/zehui127/Omni-DNA-20M) (OLMo-based, 20M params, BPE tokenizer, 250-token context)
22
+ - **Purpose**: Given a parent DNA sequence, predict the mutated child sequence
23
+ - **Format**: `"mutate: {parent} -> {child}"` β€” instruction-tuned as a causal LM
24
 
25
  ## SAD Pipeline
26
 
27
  ```
28
+ Stage 1 (ICI β€” Interleaved Codon Interference):
29
+ Dual-model consensus generation (Omni-DNA-20M + HyenaDNA tiny-1k)
30
+ Every 3 codons, a 1-codon gap is introduced; both models predict the gap
31
+ Agreement = consensus (high quality), disagreement = contested (kept, weighted lower)
32
+ β†’ Produces 8,112 synthetic mutation pairs
33
+
34
+ Stage 2 (SAD β€” Sequential Attenuation Denoising):
35
+ Fine-tune on synthetic pairs first (builds broad mutation prior)
36
+ Then fine-tune on real data at 10x lower LR
37
+ Uncontradicted synthetic patterns persist, contradicted ones get attenuated
38
  ```
39
 
40
+ ### Key Parameters
 
 
41
 
42
+ | Parameter | Value |
43
+ |-----------|-------|
44
+ | **ICI Codon Gap Distance** | 3 (every 3rd codon = 9 bp spacing) |
45
+ | **SAD Coefficient** | 4.89 (81,120 synthetic exposures / 16,585 real exposures) |
46
+ | Stage 1 LR | 5e-5, 10 epochs |
47
+ | Stage 2 LR | 1e-5, 5 epochs |
48
+ | Batch Size | 16 Γ— 2 (effective 32) |
49
+ | Precision | fp32 |
50
 
51
  ## Checkpoints
52
 
53
+ | Path | Description |
54
+ |------|-------------|
55
+ | `stage1_ici/` | Weights after synthetic pre-training (ICI stage) |
56
+ | `stage2_sad/` | Weights after real-data attenuation (final SAD model) |
57
 
58
+ ## Benchmarks (200 test pairs)
59
 
60
  | Model | Levenshtein ↓ | Similarity ↑ | Mutation Recall ↑ |
61
  |-------|:---:|:---:|:---:|
62
+ | Base Omni (no fine-tuning) | 359.2 | 44.0% | **74.3%** |
63
  | Stage 1 (synthetic only) | 260.1 | 45.1% | 67.3% |
64
+ | **Stage 2 SAD (final)** | **268.2** | **43.8%** | **67.8%** |
 
 
 
 
 
 
 
 
 
65
 
66
+ ### Known Issues
 
 
 
 
67
 
68
+ 1. **SAD coefficient too high**: At 4.89, synthetic exposures overwhelmed real data attenuation. Mutation recall dropped from base 74.3% β†’ 67.8%. A lower coefficient (~1.5) is recommended for future runs.
69
+ 2. **Synthetic mutation rate mismatch**: Synthetic data has 17.8% mean mutation rate vs 3.9% in real data β€” model learns to over-mutate.
70
+ 3. **Omni `.generate()` broken after fine-tuning**: Model outputs PAD/EOS immediately. Use manual autoregressive loop with special token suppression instead (see Usage).
71
 
72
  ## Usage
73
 
74
  ```python
 
75
  import torch
76
+ from transformers import AutoTokenizer, AutoModelForCausalLM
77
 
78
+ # Load Stage 2 (final SAD model)
79
  tokenizer = AutoTokenizer.from_pretrained("Nhoodie/omni-dna-sad-mutation", subfolder="stage2_sad", trust_remote_code=True)
80
+ model = AutoModelForCausalLM.from_pretrained("Nhoodie/omni-dna-sad-mutation", subfolder="stage2_sad", trust_remote_code=True).to("cuda").eval()
81
 
82
+ def predict_child(parent, max_new_tokens=200, temperature=0.2):
83
+ """Manual autoregressive generation (Omni .generate() outputs PAD after fine-tuning)"""
84
  prompt = f"mutate: {parent} -> "
85
+ input_ids = tokenizer(prompt, return_tensors="pt")["input_ids"].to(model.device)
86
  generated = input_ids
87
  suppress = {0, 1, 2, 3} # UNK, CLS, SEP, PAD
88
+
89
  with torch.inference_mode():
90
  for _ in range(max_new_tokens):
91
  logits = model(input_ids=generated).logits[:, -1, :] / max(temperature, 0.01)
92
+ for s in suppress:
93
+ logits[0, s] = float("-inf")
94
+ probs = torch.softmax(logits, dim=-1)
95
+ next_token = torch.multinomial(probs, num_samples=1)
96
  generated = torch.cat([generated, next_token], dim=-1)
97
+
98
  text = tokenizer.decode(generated[0, input_ids.shape[1]:], skip_special_tokens=True)
99
  return "".join(c for c in text.upper() if c in "ACGT")
100
 
101
+ parent = "ATGGCTAGCTGATCGATCGATCG..."
102
+ child = predict_child(parent)
103
+ print(child)
104
  ```
105
 
106
  ## Dataset
107
 
108
  Training data available at: [Nhoodie/omni-dna-sad-mutation-dataset](https://huggingface.co/datasets/Nhoodie/omni-dna-sad-mutation-dataset)
109
 
110
+ ## Training Hardware
 
 
 
 
 
 
 
 
111
 
112
+ - **GPU**: NVIDIA GTX 1080 8GB
113
+ - **Stage 1**: ~8 min (8,112 synthetic pairs, 10 epochs)
114
+ - **Stage 2**: ~9 min (3,317 real pairs, 5 epochs)
115
+ - **Total**: <20 min training time