Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,123 +1,115 @@
|
|
| 1 |
---
|
| 2 |
-
license:
|
| 3 |
-
base_model: zehui127/Omni-DNA-20M
|
| 4 |
tags:
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
pipeline_tag: text-generation
|
| 12 |
---
|
| 13 |
|
| 14 |
# Omni-DNA SAD Mutation Model
|
| 15 |
|
| 16 |
-
Fine-tuned
|
| 17 |
|
| 18 |
## Architecture
|
| 19 |
|
| 20 |
-
- **Base
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
|
| 24 |
## SAD Pipeline
|
| 25 |
|
| 26 |
```
|
| 27 |
-
Stage 1 (ICI
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
8,112
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
```
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
## ICI (Interleaved Codon Interleaving) β Synthetic Data Generation
|
| 38 |
|
| 39 |
-
|
| 40 |
-
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
## Checkpoints
|
| 48 |
|
| 49 |
-
| Path |
|
| 50 |
-
|------|-------
|
| 51 |
-
| `stage1_ici/` |
|
| 52 |
-
| `stage2_sad/` |
|
| 53 |
|
| 54 |
-
##
|
| 55 |
|
| 56 |
| Model | Levenshtein β | Similarity β | Mutation Recall β |
|
| 57 |
|-------|:---:|:---:|:---:|
|
| 58 |
-
|
|
| 59 |
| Stage 1 (synthetic only) | 260.1 | 45.1% | 67.3% |
|
| 60 |
-
| **Stage 2 SAD (
|
| 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 |
-
|
| 72 |
-
|---------|-------------------|
|
| 73 |
-
| Synthetic (ICI) | 17.8% |
|
| 74 |
-
| Real (train) | 3.9% |
|
| 75 |
-
| Real (test) | 0.8% |
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
|
| 79 |
## Usage
|
| 80 |
|
| 81 |
```python
|
| 82 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 83 |
import torch
|
|
|
|
| 84 |
|
| 85 |
-
# Load Stage 2 (final
|
| 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 |
-
|
| 90 |
-
|
| 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:
|
| 99 |
-
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
| 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
|
| 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 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
| 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
|