Somasays is an end-to-end computational biology framework for de novo plant-like peptide design, 3D structural folding, and inference-optimization tooling using the EvolutionaryScale ESM3 (1.4B Parameter) Multimodal Protein Foundation Model.
This repository provides a complete pipeline from raw sequence preprocessing to distributed multi-GPU training, real-time performance profiling, structural FlashAttention optimizations, and downstream biophysical evaluation.
graph TD
subgraph Data Pipeline
A[UniProt Metadata Extraction] -->|fetch_uniprot_data.py| B[Sequence Preprocessing]
B -->|preprocess_sequences.py| C[AlphaFold 3D Cache]
end
subgraph Distributed Training
C -->|esm3_lora_finetune.py| D[Distributed Data Parallel DDP]
D -->|NCCL, Static Graph, BF16 AMP| E[Fine-Tuned Adapter Weights]
end
subgraph Optimization & Generation
E -->|generate_candidates.py| F[Optimized ESM3 Generator]
F -->|ProteinMPNN sequence rescue| G[Candidate Sequences]
G -->|evolutionary_optimizer.py| H[In Silico Directed Evolution]
H -->|Simulated Annealing + pI / GRAVY / MHC Filters| I[Evolved Cysteine-Free Candidates]
end
subgraph Downstream Validation & Serving
I -->|evaluate_cysteine_free_complexes.py| K[Joint WLSS Evaluation Pipeline]
K -->|Calculates WLSS score| L[Wet-Lab Success Leaderboard]
I -->|api_service/server.py| J[FastAPI Model Serving API]
end
-
High-Throughput Distributed Fine-Tuning:
- Multi-GPU distributed training using PyTorch Distributed Data Parallel (DDP) with NCCL communication backends.
- Leverages transformer gradient checkpointing and compiles a static computation graph topology (
_set_static_graph()) to eliminate graph re-entrancy overhead. - Integrates pre-cached data-loading entirely in host memory (100GB Host RAM pre-caching) to eliminate disk I/O bottlenecks.
-
Inference Optimization Tooling:
- System-level Scaled Dot Product Attention (SDPA) backend configuration forcing FlashAttention-2 execution, reducing matrix complexity from quadratic
$O(N^2)$ to linear$O(N)$ . - Automatic Mixed Precision (AMP) utilizing hardware bfloat16 Tensor Cores for memory-efficient and accelerated execution.
- Low-precision casting configuration interfaces (bfloat16/float16).
- System-level Scaled Dot Product Attention (SDPA) backend configuration forcing FlashAttention-2 execution, reducing matrix complexity from quadratic
-
High-Resolution Performance Profiling:
- Low-overhead GPU profiler tracking token-by-token latency, VRAM footprint allocation, and residue generation throughput curves.
- Automated benchmark suites sweeping protein sequence contexts up to 2,048 residues.
-
In Silico Directed Evolution Engine:
- Simulated annealing sequence search loop to optimize monomer folding stability (
$\Delta G$ ) using a 3-model SaProtΔG ensemble. - Implements strict biophysical constraint checks in the active search loop:
-
pI Filter: Automatically rejects sequences with an isoelectric point inside the physiological pH precipitation zone (
$6.8 \le pI \le 8.0$ ). - Solubility Filter: GRAVY hydropathy index cannot exceed a baseline limit (0.45).
- MHC-II Immunogenicity Filter: Ensures no new HLA-DRB1 binding core epitopes are introduced.
- Thiol-free Constraint: Enforces 100% cysteine-free designs to prevent uncontrolled disulfide aggregation in wet-lab assays.
-
pI Filter: Automatically rejects sequences with an isoelectric point inside the physiological pH precipitation zone (
- Simulated annealing sequence search loop to optimize monomer folding stability (
-
Joint Wet-Lab Success Scoring (WLSS):
- Consolidates multi-parameter metrics into a single Wet-Lab Success Score (WLSS): 50% target binding kinetics, 30% folding energy, and 20% manufacturability.
- Scans for post-translational modification (PTM) risk hotspots (glycosylation, deamidation, acid cleavage, methionine oxidation), hydrophobic patches, and estimates cyclization feasibility.
Somasays/
├── api_service/ # Atlassian-inspired Model Serving Edge Service
│ ├── server.py # FastAPI web server, routing & polling schema
│ └── tasks.db # Decoupled task queue state tracking
├── data_pipeline/ # Data ingestion & caching
│ ├── fetch_uniprot_data.py # Extracts raw metadata and sequence strings
│ ├── preprocess_sequences.py # Standardizes sequences for tokenization
│ └── fetch_alphafold_structures.py # Pulls PDB coordinates from AlphaFold DB
├── model_training/ # Heavy GPU training scripts
│ ├── training_config.yaml # Core hyperparameters configuration
│ ├── esm3_lora_finetune.py # PEFT Masked Language Modeling
│ └── esm3_multimodal_trainer.py # Distributed Multimodal DDP training
├── generation_engine/ # Synthesis and performance optimization
│ ├── generate_candidates.py # MLM peptide sampling
│ ├── esm3_multimodal_generator.py # Dual-track sequence & coordinate generator
│ ├── optimized_inference.py # FlashAttention SDPA / AMP optimization wrapper
│ └── profile_inference.py # Latency and peak VRAM profiling engine
├── evaluation_and_rescue/ # Downstream verification
│ ├── evolutionary_optimizer.py # Simulated annealing directed evolution
│ ├── evaluate_cysteine_free_complexes.py # Joint WLSS validation pipeline
│ ├── proteinmpnn_rescue.py # Backbone sequence co-design
│ ├── mpnn_stability_rescue.py # Stability optimization scripts
│ ├── candidate_rescuer.py # Rescues wildtypes using ProteinMPNN
│ ├── cysteine_free_rescuer.py # Mutates cysteines and evaluates stability
│ ├── manufacturability_profiler.py # Biophysical risk assessment profiler
│ ├── binding_interface_analyzer.py # Parses complexes for contact maps, ipTM & pLDDT
│ ├── codon_optimizer_carbon.py # Codon optimization (E. coli & Human expression)
│ ├── structural_qc.py # MHC-II epitope prediction using absolute stability methods
│ └── umap_embedding_analysis.py # Synthesized space embedding projection
├── analysis/ # Benchmarking suite & visualizers
│ ├── benchmark_suite.py # Auto-sweeps lengths, batch sizes & configs
│ ├── plot_convergence_curves.py # Visualizes training loss curves
│ └── outputs/ # Latency, throughput, and memory charts
├── README.md # Platform overview & execution guide
└── optimizations_case_study.md # Professional ESM3 performance report
Ensure your environment contains CUDA 12+ and PyTorch 2.0+ with matching drivers:
# Activate virtual environment
source venv_somasays/bin/activate
# Install core packages
pip install torch torchvision torchaudio esm biopython matplotlib pandas --quietProfile the latency and VRAM footprint of sequence autoregression and coordinate folding under baseline configurations:
python generation_engine/profile_inference.py --prompt "MKA___________________VLA" --steps 8Sweep sequence lengths up to 2,048 residues to generate comparative line charts mapping latency, throughput, and VRAM efficiency:
python analysis/benchmark_suite.py --outdir analysis/outputsSpin up the systems-optimized model serving API. This utilizes a decoupled, asynchronous queue architecture to isolate heavy GPU inference tasks:
# Install server dependencies
pip install fastapi uvicorn pydantic --quiet
# Launch the FastAPI web engine
uvicorn api_service.server:app --host 0.0.0.0 --port 8000 --reload-
Submit a folding/generation task:
curl -X POST "http://localhost:8000/v1/tasks" \ -H "Content-Type: application/json" \ -d "{\"prompt_sequence\": \"MKA___________________VLA\", \"num_steps\": 8, \"temperature\": 0.7}"
Response:
{"task_id": "a90f117c-...", "status": "PENDING", ...} -
Poll for completion and coordinate outputs:
curl "http://localhost:8000/v1/tasks/<task_id>"
Execute the simulated annealing directed evolution search starting from a baseline sequence to maximize folding stability under biophysical constraints (no cysteines, safe pI, solubility, non-immunogenic):
python evaluation_and_rescue/evolutionary_optimizer.py --steps 50 --output outputs/evolution_history.csvCompile structural and biophysical characteristics for all generated candidates into a ranked leaderboard scoring Wet-Lab Success Score (WLSS):
python evaluation_and_rescue/evaluate_cysteine_free_complexes.py \
--in_dir outputs/combined_runs \
--out_dir outputsThis generates outputs/joint_evaluation_report.md (leaderboard) and outputs/joint_evaluation_report.csv.
Evaluate designed candidates for glycosylation traps, deamidation, acid cleavage susceptibility, and GRAVY hydropathy:
python evaluation_and_rescue/manufacturability_profiler.py \
--in_dir outputs/mpnn_best_sequences \
--out_dir outputsParse PDB structural complexes and confidence JSONs to compute contact maps, hydrogen bonds, salt bridges, pLDDT scores, and ipTM rankings:
python evaluation_and_rescue/binding_interface_analyzer.py \
--in_dir outputs/af3_results \
--out_dir outputs \
--binder_chain AConvert the designed peptide amino acid sequence into expression-optimized DNA sequences for target host expression systems (E. coli or Human) to maximize protein yield:
python evaluation_and_rescue/codon_optimizer_carbon.py \
--in_seq MKARRLAAGLLAAAEEAKKAAPVLA \
--host ecoli \
--out_file outputs/top_lead_codon_optimized.csvRun the Seaborn-based plotting suite to compile and refresh the design space, optimization trajectory, and biophysical heatmap figures:
python evaluation_and_rescue/plot_scientific_insights.pyOur structural modeling sweeps indicate that combining bfloat16 AMP with FlashAttention (SDPA) significantly scales execution limits on NVIDIA L4/A100 hardware profiles:
- 3.4x Projected Speedup: Projected execution latency during structural folding loops scales linearly rather than quadratically.
- 58% Memory Savings: Projected peak VRAM footprint at 1,024 residues falls from 14.6 GB to 5.9 GB.
- Increased Sequence Context: Designed to mitigate memory-related Out-of-Memory (OOM) failures for sequences up to 2,048 residues.
For a complete breakdown of optimization methodologies, theoretical scaling profiles, and benchmark simulation scripts, read our full ESM3 Optimization and Performance Case Study.
| Design Space Landscape | Directed Evolution Trajectory | Biophysical Heatmap Leaderboard |
|---|---|---|
![]() |
![]() |
![]() |
To elevate Somasays into a fully automated, web-scale biological factory, the following roadmap features are planned for future development:
-
Dynamic Tensor Parallelism (TP):
- Integrate DeepSpeed or Megatron-LM to shard the 1.4B parameters and attention matrices across multiple GPU nodes. This will enable structural folding of large multi-domain complexes exceeding 4,000 residues.
-
Hopper Native FP8 & FlashAttention-3:
- Migrate SDPA backends to native FlashAttention-3 kernels on Hopper GPU architectures (H100/H200). This will utilize low-precision FP8 Tensor Cores to speed up sequential autoregressive decoding.
-
8-Bit and 4-Bit Weight Quantization:
- Integrate 8-bit and 4-bit NormalFloat (NF4) loading configurations using
bitsandbytes. This will compress the active model footprint to enable foundation model inference on consumer-grade GPUs.
- Integrate 8-bit and 4-bit NormalFloat (NF4) loading configurations using
-
Asynchronous AlphaFold 3 API Loop:
- Build a background daemon to automatically submit generated protein coordinates to the AlphaFold 3 server, parse confidence metrics (pLDDT, iPAE), and store results in a PostgreSQL database for real-time downstream validation.
-
Speculative Speculative Decoding (SSD) / Saguaro Integration:
- Incorporate asynchronous draft-target token co-speculation. Deploy a lightweight sequence draft model (e.g., ESM-2 35M) in parallel with the target ESM3 model using non-blocking PyTorch CUDA streams and Saguaro sampling (top-logit downweighting) to eliminate sequential drafting bottlenecks and accelerate sequence generation by
$2\times$ to$3\times$ without quality degradation.
- Incorporate asynchronous draft-target token co-speculation. Deploy a lightweight sequence draft model (e.g., ESM-2 35M) in parallel with the target ESM3 model using non-blocking PyTorch CUDA streams and Saguaro sampling (top-logit downweighting) to eliminate sequential drafting bottlenecks and accelerate sequence generation by



