How evolutionaryscale/esm works
Main Components
• Core Modeling Library:
– The “esm/layers” and “esm/models” directories encapsulate the neural network layers (attention, feed-forward, geometry, transformer stacks, etc.) and the model implementations (ESM3, ESM C, function_decoder, vqvae, etc.).
– These components represent the core computation and inference logic of the protein models.
• Data Handling and Tokenization:
– The “esm/data” subdirectory stores reference files (e.g., vocabulary lists, csv and text files for interpro, etc.) that drive the input and output token representation.
– The “esm/tokenization” module provides various tokenizers (for sequences, residues, structures, SASA, and secondary structure) that convert protein data into discrete tokens for model processing.
• SDK and Client Interfaces:
– In “esm/sdk” you find the API modules for interacting with the models – including local API clients, Forge API integration (“esm/sdk/forge.py”), and SageMaker utilities (“esm/sdk/sagemaker.py”).
– This layer abstracts away the deployment choice, allowing the same interface to be used for local and remote inference.
• Utility Functions and Helpers:
– “esm/utils” (including constants, functions, decoding/encoding routines, generation utilities, and structure utilities) supports the core layers by providing preprocessing, postprocessing, and additional computation support.
• Widgets and Visualization:
– The “esm/widgets” directory shows that the project also includes some components dedicated to visualization and UI – which may be used for interactive applications or web-based explorations of protein predictions.
• Notebooks and Tutorials (“cookbook” and “tools” directories):
– The “cookbook” folder (with local notebooks, snippets, and tutorials) and “tools” notebooks are demonstrative and educational pieces designed to show how to use the library across various scenarios. They serve as both usage examples and testing environments, connecting the API with end-user workflows.
Relationships and Data Flow
• Data flows from input protein sequences (and possibly prompts that include structure or function tokens) through the tokenization layer.
• The tokenized data is then processed by the core models. Here, the “layers” and “models” perform forward passes (and iterative sampling for generative tasks).
• Post-processing happens in the “utils” modules (for decoding, structure prediction, etc.), and results can be visualized via the “widgets” components.
• The SDK layer provides a unified interface to call these components, whether executing models locally – fetching and loading pretrained weights (from HuggingFace or local files) – or via remote inference methods (through Forge or SageMaker APIs).
Architectural Patterns and Design Principles
• Modular Design: The separation between data, layers, models, tokenizers, and utilities reflects a clean modular design using separation of concerns.
• Unified API Abstraction: The SDK ensures that users can swap between local computation and remote API calls (Forge or SageMaker) with minimal code changes.
• Extensibility: The well-organized “cookbook” demos and “tutorials” suggest that the system is intended to be extended, with standardized components that can be replaced or improved individually.
Detailing Architectural Elements
• Every component is well-labeled and that dependencies are indicated (e.g., “esm/models” depends on “esm/layers” and “esm/tokenization”, and “esm/sdk” interacts with “esm/models” for API calls).
• HuggingFace Hub (for model weights)
• EvolutionaryScale Forge API (remote inference)
• AWS SageMaker (for commercial inference)