File size: 5,717 Bytes
88b2e4a
 
 
 
 
 
 
 
 
 
 
 
 
 
83ddd7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88b2e4a
 
 
 
 
 
 
 
 
 
 
83ddd7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
library_name: transformers
pipeline_tag: text-generation
tags:
  - biology
  - genomics
  - rna
  - sequence-generation
  - regression
  - reinforcement-learning
  - safetensors
  - git-lfs
---

# RNASeek Full

This repository contains code, model checkpoints, notebooks, and data artifacts for RNA sequence generation and regression workflows used in the RNASeek project.

## Repository Layout

- `efficiency_figure2/` - sequence efficiency regression training scripts, input JSON/JSONL files, TensorBoard logs, and checkpoints.
- `regression_stability_functionalviral/` - functional viral element stability regression data, alignment/count summaries, notebooks, training scripts, and checkpoints.
- `ribozymegen-figure7/` - supervised ribozyme causal language model fine-tuning inputs and scripts.
- `ribozymegen-rl-figure7/` - ribozyme reinforcement learning scripts using reward model and directive scoring HTTP APIs.
- `utrgen/` - supervised UTR causal language model fine-tuning scripts, train/validation text files, and checkpoints.
- `utrgen-rl.zip` - archived UTR reinforcement learning workflow. The raw `utrgen-rl/` directory is intentionally distributed as this zip artifact because of its size.
- `requirements.txt` - frozen Python package list from the environment used to prepare this release.

## Environment

Create and activate a Python environment, then install the frozen dependencies:

```bash
pip install -r requirements.txt
```

If you need FlashAttention, use a CUDA/PyTorch-compatible build. Prebuilt wheel
instructions are available at
https://github.com/mjun0812/flash-attention-prebuild-wheels.

The portable runtime is distributed as `portable_runtime.tar.gz`. Extract it
before using commands that reference `portable_runtime/env/bin/python`:

```bash
tar -xzf portable_runtime.tar.gz
```

Most training scripts expect CUDA-enabled PyTorch and access to local model checkpoints referenced by each script's path constants. Review the path variables at the top of each script before launching a run.

## Common Entry Points

Supervised language-model fine-tuning:

```bash
cd utrgen
python3 train.py
```

```bash
cd ribozymegen-figure7
python3 train.py
```

Regression model training:

```bash
cd efficiency_figure2
python3 betterTrain.py
```

```bash
cd regression_stability_functionalviral
python3 betterTrain.py
```

## Packed Regression Model Validation

Model weight files are stored in ZIP archives on the Hub as
`*.safetensors.zip`. Restore them before loading checkpoints:

```bash
python3 scripts/unzip_safetensors.py --overwrite
```

or:

```bash
./scripts/unzip_safetensors.sh
```

The efficiency and stability regression checkpoints include the regression head inside
the model checkpoint directory as `regression_head.safetensors`. The checkpoint index
maps the packed head tensors under `regression_head.*`, while the original
`regression_head.pt` remains as a fallback for older scripts.

Run validation from the repository root. To force CPU-only evaluation, clear
`CUDA_VISIBLE_DEVICES` and pass `--device cpu`:

```bash
CUDA_VISIBLE_DEVICES= MPLCONFIGDIR=/tmp/matplotlib-rnaseek \
  portable_runtime/env/bin/python \
  efficiency_figure2/validate_packed_regression_model.py \
  --device cpu \
  --batch-size 16
```

This writes:

- `efficiency_figure2/packed_validation/valid_predictions.tsv`
- `efficiency_figure2/packed_validation/valid_metrics.json`
- `efficiency_figure2/packed_validation/valid_scatter.png`

The efficiency validator defaults to:

- model: `efficiency_figure2/qwen_regression_ckpt/clean_cosine_restart_besthp_preview_fixed-wd-0.9_reproduce/checkpoint-304419`
- tokenizer: the same checkpoint directory, unless `--tokenizer-dir` is provided
- validation data: `efficiency_figure2/evenBetterDataFolded-vl.json`

Run the stability packed model validation the same way:

```bash
CUDA_VISIBLE_DEVICES= MPLCONFIGDIR=/tmp/matplotlib-rnaseek \
  portable_runtime/env/bin/python \
  regression_stability_functionalviral/validate_packed_regression_model.py \
  --device cpu \
  --batch-size 4
```

This writes:

- `regression_stability_functionalviral/packed_validation/valid_predictions.tsv`
- `regression_stability_functionalviral/packed_validation/valid_metrics.json`
- `regression_stability_functionalviral/packed_validation/valid_scatter.png`

The stability validator defaults to:

- model: `regression_stability_functionalviral/checkpoint-44040_best`
- tokenizer: `regression_stability_functionalviral/checkpoint-388560_base`
- validation data: `regression_stability_functionalviral/training_seq_score_extreme_weighted.tsv` with `split == "val"`

To repack a regression head after replacing `regression_head.pt`, run:

```bash
portable_runtime/env/bin/python scripts/pack_regression_head_into_safetensors_index.py \
  path/to/checkpoint
```

The packer writes `regression_head.safetensors` and updates
`model.safetensors.index.json` so packed-model loaders can discover the head.

UTR GRPO reinforcement learning uses a separate reward-model API process:

```bash
cd utrgen-rl
CUDA_VISIBLE_DEVICES=1 python3 rm_evaluator_api.py --device cuda:0 --port 8008
CUDA_VISIBLE_DEVICES=0 python3 train_grpo.py --rm-api-url http://127.0.0.1:8008
```

Ribozyme GRPO reinforcement learning expects reward and directive scoring services matching the endpoints configured in `ribozymegen-rl-figure7/testgrpo_retry-linearblend_prior.py`.

## Notes

- Scripts are research-oriented and expose run settings as constants near the top of each file.
- Notebook checkpoint folders, TensorBoard logs, and model checkpoints are included where present in the release artifact.
- The raw `utrgen-rl/` directory is not required for Hub upload when `utrgen-rl.zip` is present.