How qhuang20/gflownet-seq-gen works
1. What this repository is
- This is a research codebase for GFlowNet-based RNA sequence generation.
- The main goal is to train models that generate sequences proportional to a biological reward, especially for the LET-7 miRNA family across species.
2. Primary runtime and entry points
- The repo is Python-first, with experiments run through notebooks and one main training script: train_LET7_22bp.py.
- The notebooks split the workflow into training, GPU training, and downstream analysis, so the architecture is centered on experiment orchestration, not on a long-running service.
3. Core model subsystem: gfn/
- gfn/ contains the reusable GFlowNet implementation.
- env.py defines the state space and sequence construction dynamics.
- model.py defines the parameterized policies / networks used for TB and DB variants.
- losses.py implements the GFlowNet objectives.
- training.py and training_fast.py are the two training loops: a standard episode-based loop and a GPU-batched accelerated path.
4. Reward and objective boundary
- gfn/reward.py is the main boundary between the biological problem definition and the GFlowNet core.
- Reward functions encode sequence-matching criteria such as:
- Hamming-style target matching
- entropy-weighted scoring
- conservation-aware scoring
- This separation lets the same training engine optimize different biological target formulations.
5. Data assets and target generation
- data/ holds both static biological inputs and derived target sets.
- Inputs include FASTA files for LET-7 family sequences across species and subtree-specific sequences.
- JSON and .py files in the same folder represent precomputed target collections and generation utilities, showing a pipeline from raw sequence data to training-ready targets.
6. Data preparation pipeline
- Scripts like generate_targets.py, generate_LET7_22bp_targets.py, and targets_10bp.py suggest a preprocessing stage that:
- extracts subsequences or motifs,
- filters/normalizes targets,
- serializes them into JSON for training.
- This preprocessing is a distinct upstream layer from model training, and the trained system consumes these prepared target sets rather than raw phylogenetic data directly.
7. Training flow
- Training begins with a target set and reward definition, then the GFlowNet learns a distribution over sequences that matches those rewards.
- The main data flow is:
- biological sequence targets → reward evaluation → GFlowNet sampling/update loop → learned sequence generator.
- The code supports multiple objectives: TB, DB, and FL-DB, so the architecture includes objective-specific loss computation under a shared environment/model backbone.
8. GPU scaling path
- gfn/training_fast.py and the GPU-oriented notebooks indicate a separate execution path for batch-based accelerated training.
- This is important architecturally because the repo supports both:
- smaller exploratory runs in notebooks, and
- larger production-style experiments for LET-7 on GPU.
9. Analysis and visualization
- gfn/visualization.py and the analysis notebooks are downstream consumers of training outputs.
- They appear to inspect:
- hit trajectories,
- sequence generation quality,
- phylogenetic coverage,
- and search behavior such as greedy, stochastic, or beam-like generation.
- This is a distinct post-training analysis layer rather than part of the learning loop itself.
10. Phylogeny subsystem
- phylogeny/ contains a notebook and a shell pipeline for phylogenetic analysis.
- That subsystem is used to contextualize generated sequences against evolutionary relationships, supporting the “AncestorGFN” framing.
- In an architecture diagram, this should be shown as an auxiliary analysis branch fed by sequence data and model outputs.
11. Experiment organization
- The repo is structured around reproducible experiment notebooks:
- toy 4bp training,
- 10bp target training,
- LET-7 22bp long runs,
- conservation-focused variants.
- These notebooks are not just documentation; they serve as the primary orchestration layer for switching between target sets, objectives, and training scales.
12. Key architectural boundary
- The most important boundary is between:
- biological data + reward specification on one side, and
- GFlowNet training/inference on the other.
- The outputs are not classifiers or predictors, but generated RNA sequences and trajectories sampled from a learned reward-proportional distribution.
Main entry points: training.py Training loop · generate_targets.py Target builders · reward.py Reward rules · training_fast.py GPU trainer
Components 18
Data & targets
Biological sequence inputs, derived target sets, and target-generation scripts.
- Raw sequences · LET-7 family and subtree sequence corpora used as biological source material.
data/LET7_family_mature_ALLspecies.fa - Unique species · Deduplicated LET-7 mature sequences across species.
data/LET7_family_mature_ALLspecies_UNIQUEspecies.fa - 10bp targets · Prepared 10bp target collections used for smaller experiments.
data/targets_10bp.json - 22bp targets · Prepared LET-7 22bp target collections for the main long-run experiments.
data/LET7_22bp_targets.json - P2b3 set · Subtree-derived sequences and targets for a phylogenetic branch experiment.
data/P2b3_targets.json - Target builders · Scripts that extract, filter, normalize, and serialize training targets from raw sequence data.
data/generate_targets.py
GFlowNet core
Reusable environment, reward, model, objective, and training code.
- Sequence env · Defines the sequence construction state space and transition rules.
gfn/env.py - Reward rules · Encodes target matching, entropy-aware, and conservation-aware reward functions.
gfn/reward.py - Policies · Parameterized policies and networks used by trajectory balance and detailed balance variants.
gfn/model.py - Objectives · Implements training objectives for TB, DB, and FL-DB style optimization.
gfn/losses.py - Training loop · Standard training loop for iterative sequence sampling and parameter updates.
gfn/training.py - GPU trainer · Accelerated GPU-oriented training path for larger experiments and higher throughput.
gfn/training_fast.py - Visual tools · Visualization utilities for trajectories, generation quality, and search behavior.
gfn/visualization.py
Experiment orchestration
Notebooks and scripts that configure training and analysis runs.
- LET7 train · Main Python entry point for LET-7 22bp training runs.
train_LET7_22bp.py - Train notebooks · Notebook-based training workflows for toy, 10bp, and LET-7 variants.
run_training.ipynb - GPU notebooks · Notebook workflows for accelerated GPU training and long-running experiments.
run_training_gpu.ipynb - Analysis notebooks · Downstream notebooks for inspecting outputs, hits, and sequence design behavior.
run_analysis.ipynb
Phylogeny analysis
Auxiliary evolutionary analysis pipeline for interpreting generated sequences.
- Phylogeny pipeline · Shell and notebook pipeline for evolutionary context and AncestorGFN-style analysis.
phylogeny/phylogeny_pipeline.sh
Connections 24
- Target builders → 10bp targets: builds · Generates curated 10bp target sets from raw inputs.
- Target builders → 22bp targets: builds · Generates LET-7 22bp targets used for training.
- Target builders → P2b3 set: builds · Produces subtree-specific targets and sequence collections.
- Raw sequences → Target builders: inputs · Raw FASTA sequence corpora feed preprocessing.
- Unique species → Target builders: inputs · Deduplicated species sequences are another preprocessing source.
- 10bp targets → Reward rules: drives · Target collections define reward matching objectives.
- 22bp targets → Reward rules: drives · Main LET-7 targets are scored by reward functions.
- P2b3 set → Reward rules: drives · Subtree targets inform conservation or branch-aware scoring.
- Reward rules → Objectives: optimizes · Reward evaluations are used inside GFlowNet objectives.
- Sequence env → Policies: conditions · Model policies act over the sequence construction environment.
- Policies → Objectives: trained by · Policy parameters are updated through GFlowNet losses.
- Sequence env → Training loop: simulates · Training loop repeatedly rolls out sequence trajectories.
- Reward rules → Training loop: scores · Training consumes biological rewards for sampled sequences.
- Objectives → Training loop: updates · Objectives produce gradients for the standard loop.
- GPU trainer → Training loop: accelerates · GPU path is a higher-throughput implementation of the same training flow.
- LET7 train → GPU trainer: runs · Main script launches the accelerated LET-7 training path.
- Train notebooks → Training loop: orchestrates · Notebook runs configure and launch standard experiments.
- GPU notebooks → GPU trainer: orchestrates · GPU notebooks drive accelerated long-run training.
- Analysis notebooks → Visual tools: consumes · Analysis notebooks render trajectories and sequence-quality summaries.
- Training loop → Visual tools: outputs · Training produces artifacts consumed by visualization utilities.
- GPU trainer → Visual tools: outputs · GPU training also feeds downstream inspection and plotting.
- Visual tools → Phylogeny pipeline: contextualizes · Visualization and outputs are interpreted with phylogenetic analysis.
- Raw sequences → Phylogeny pipeline: context · Raw sequence corpora support evolutionary interpretation.
- LET7 train → Analysis notebooks: compares · Main experiments are typically followed by notebook-based analysis.