# ai4healthuol/ecg-fm-benchmarking architecture

> Architecture diagram of the GitHub repository ai4healthuol/ecg-fm-benchmarking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ai4healthuol/ecg-fm-benchmarking
- Repository: https://github.com/ai4healthuol/ecg-fm-benchmarking

## Overview

This repository is a benchmarking and training framework for ECG-centric time-series foundation models, with some support for EEG and movement signals. The architecture is organized around a shared clinical time-series core, plus dataset-specific configuration and model wrappers for evaluating many pretrained checkpoints on many downstream tasks.

1. **Top-level workflow**
   The repo has two main execution paths:
   - **Benchmark/evaluation** via `main_lite.py`, `main_lite_ecg.py`, `main_lite_eeg.py`, `main_lite_movement.py`
   - **Pretraining** via `pretrain.py`
   
   These scripts sit on top of the `clinical_ts` package and are the main entry points for running experiments.

2. **Data ingestion and preprocessing**
   Raw datasets are not stored in code; the repository expects preprocessed dataset artifacts produced externally, mainly through:
   - `preprocess_ecg_dataset.ipynb`
   - `mimic_preprocessing.py`
   
   The data pipeline is driven by dataset-specific YAML configs under `code/conf/data` and `code/clinical_ts/models/conf/data`. The README also points to label-mapping spreadsheets and MIMIC-IV-ECG CSVs, which are part of the data preparation boundary.

3. **Clinical time-series core package**
   `code/clinical_ts` is the central library. It contains the reusable building blocks shared across all tasks:
   - `data/` for dataset objects, transforms, and utilities
   - `models/` for supervised and foundation-model wrappers
   - `loss/` and `metric/` for task objectives and evaluation
   - `task/` for task-specific orchestration
   - `utils/` for preprocessing, scheduling, evaluation, and helper functions

   This is the main abstraction layer that separates dataset handling, model definition, and experiment execution.

4. **Dataset layer**
   `time_series_dataset.py`, `time_series_dataset_transforms.py`, and `time_series_dataset_utils.py` define how signals and labels are loaded, normalized, sliced, and augmented. The dataset layer appears designed to support multiple modalities and multiple task types, with configuration rather than hard-coded dataset logic.

5. **Task orchestration**
   `code/clinical_ts/task/ecg.py` and the `main_lite_*` scripts likely assemble the full experiment for a specific modality/task family. This layer is where a dataset, model, loss, and metrics are bound together into a runnable benchmark. It is the boundary between generic infrastructure and ECG-specific benchmark logic.

6. **Model families**
   The repository supports both classic supervised architectures and foundation-model adapters:
   - Lightweight supervised backbones such as `basic_conv1d`, `inception1d`, `xresnet1d`, `s4_model`, `s42`
   - A common `template_model.py` / `template_modules.py` pattern for modular model construction
   - Specialized ECG foundation model wrappers under `models/ecg_foundation_models/`

   This separation suggests a plug-in style architecture where downstream tasks can swap encoders while keeping the rest of the pipeline stable.

7. **Foundation model implementations**
   The ECG foundation-model area contains multiple model-specific subpackages:
   - `ecg_cpc`
   - `ecg_jepa`
   - `hubert_ecg`
   - `st_mem`
   - `merl`
   - `ecgfm_ked`
   - `ecg_founder`
   
   These packages each encapsulate their own backbone/config/utility code, indicating that pretrained checkpoints from different research groups are integrated through wrappers rather than a single unified backbone implementation.

8. **Shared encoder/head abstractions**
   The `clinical_ts/ts/` and `clinical_ts/utils/heads.py` modules indicate a decomposition into:
   - an encoder/backbone that converts time series to latent representations
   - a head that maps representations to classification/regression outputs
   
   This is important for diagramming because the benchmark likely reuses the same task head interface across many model types and datasets.

9. **Losses and metrics**
   `loss/supervised.py` and `loss/selfsupervised.py` split objective functions by training regime. `metric/base.py` and utility evaluators under `utils/` provide task-specific evaluation for classification, regression, and clinical benchmark reporting. This supports both pretraining objectives and downstream fine-tuning/evaluation.

10. **Configuration system**
   The repository uses many YAML configuration files rather than hard-coded experiment setup:
   - global/run configs under `code/conf`
   - model/data configs under `code/clinical_ts/models/conf`
   - one data config per dataset/split/subject group for the benchmark
   
   The architecture is configuration-driven, which is critical for reproducing the benchmark across 12 datasets and 26 tasks.

11. **Experimental infrastructure**
   There are two native extensions under `code/extensions/`:
   - `cauchy/` with C++/CUDA code and benchmarking/tuning scripts
   - `kernels/`
   
   These are performance-oriented compute boundaries, likely used for accelerating specialized kernels in some models. They are optional infrastructure rather than core application logic, but they matter if you are drawing a diagram that includes training-time acceleration.

12. **External assets and checkpoints**
   The benchmark depends on externally downloaded pretrained checkpoints for ECG-CPC, ECGFounder, ECG-JEPA, ST-MEM, MERL, ECGFM-KED, HuBERT-ECG, and ECG-FM. The repo is therefore not just training code; it is also a model-evaluation harness over third-party pretrained assets.

13. **Output and evaluation boundary**
   The benchmark is focused on downstream performance reporting across many tasks, including regression and classification. The output boundary is therefore experiment results rather than an application UI or inference service. The presence of `Confidence_Interval.xlsx` suggests some postprocessing/statistical analysis outside the main training loop.

14. **Runtime and tooling**
   The project is Python-based and appears designed for scripted batch execution, with `sbatch run.sh` in the README indicating HPC/Slurm usage. Environment files (`env.yaml`, `ecg_fm_env.yaml`) define the runtime dependencies, and the repo is organized for reproducible offline experimentation rather than interactive serving.

Overall, the architecture is: raw clinical time-series data -> preprocessing -> dataset/config loading -> shared time-series pipeline -> chosen model family/backbone -> task head -> loss/metrics -> benchmark results. The main architectural boundary is between dataset/task orchestration and the interchangeable model implementations, especially the multiple foundation-model adapters.

Main entry points: [`code/clinical_ts/models/fm_ecg.py`](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_ecg.py) (ECG FM), [`code/clinical_ts/task/ecg.py`](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/task/ecg.py) (ECG task), [`code/clinical_ts/data/time_series_dataset.py`](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset.py) (Datasets), [`code/clinical_ts/template_model.py`](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/template_model.py) (Template model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_entry["Entry points"]
  node_n_main_lite["Main lite<br/>benchmark entry<br/>[main_lite.py]"]
  node_n_main_ecg["ECG lite<br/>benchmark entry<br/>[main_lite_ecg.py]"]
  node_n_main_eeg["EEG lite<br/>benchmark entry<br/>[main_lite_eeg.py]"]
  node_n_main_movement["Move lite<br/>benchmark entry"]
  node_n_pretrain["Pretrain<br/>training entry<br/>[pretrain.py]"]
end

subgraph group_g_core["Clinical TS core"]
  node_n_dataset[("Datasets<br/>data pipeline")]
  node_n_transforms["Transforms<br/>augmentation pipeline"]
  node_n_ds_utils["Data utils<br/>dataset utilities"]
  node_n_task_ecg["ECG task<br/>task orchestration<br/>[ecg.py]"]
  node_n_template["Template model<br/>model scaffold<br/>[template_model.py]"]
  node_n_encoder["Encoder<br/>representation layer<br/>[encoder.py]"]
  node_n_head["Task head<br/>prediction head<br/>[head.py]"]
  node_n_losses["Losses<br/>objective layer<br/>[supervised.py]"]
  node_n_metrics["Metrics<br/>evaluation layer<br/>[base.py]"]
end

subgraph group_g_fm["Foundation models"]
  node_n_basic_conv["Conv1D<br/>supervised backbone<br/>[basic_conv1d.py]"]
  node_n_s4["S4 family<br/>sequence backbone<br/>[s4_model.py]"]
  node_n_xresnet["XResNet<br/>supervised backbone<br/>[xresnet1d.py]"]
  node_n_fm_ecg["ECG FM<br/>foundation wrapper<br/>[fm_ecg.py]"]
  node_n_fm_eeg["EEG FM<br/>foundation wrapper<br/>[fm_eeg.py]"]
  node_n_fm_move["Move FM<br/>foundation wrapper<br/>[fm_movement.py]"]
  node_n_ecg_founder["Founder<br/>pretrained adapter<br/>[ecg_founder.py]"]
  node_n_ecg_cpc["ECG CPC<br/>pretrained adapter<br/>[basic_io.py]"]
  node_n_ecg_jepa["ECG JEPA<br/>pretrained adapter<br/>[ecg_jepa.py]"]
  node_n_hubert["HuBERT ECG<br/>pretrained adapter<br/>[hubert_ecg.py]"]
  node_n_stmem["ST-MEM<br/>pretrained adapter<br/>[st_mem.py]"]
  node_n_merl["MERL<br/>pretrained adapter<br/>[resnet1d.py]"]
  node_n_ked["ECGFM-KED<br/>pretrained adapter<br/>[ecgfm_ked.py]"]
end

subgraph group_g_cfg["Configuration"]
  node_n_cfg_run["Run config<br/>yaml config"]
  node_n_cfg_data["Data configs<br/>yaml configs"]
  node_n_model_cfg["Model cfg<br/>yaml config<br/>[ecg_ptbxl.yaml]"]
end

subgraph group_g_ext["Extensions"]
  node_n_cauchy["Cauchy<br/>native extension<br/>[cauchy.cpp]"]
  node_n_kernels["Kernels<br/>native extension<br/>[setup.py]"]
end

node_n_main_lite -->|"orchestrates"| node_n_task_ecg
node_n_main_ecg -->|"orchestrates"| node_n_task_ecg
node_n_main_eeg -->|"selects"| node_n_fm_eeg
node_n_main_movement -->|"selects"| node_n_fm_move
node_n_pretrain -->|"builds"| node_n_template
node_n_pretrain -->|"optimizes"| node_n_losses
node_n_task_ecg -->|"loads"| node_n_dataset
node_n_task_ecg -->|"applies"| node_n_transforms
node_n_task_ecg -->|"reports"| node_n_metrics
node_n_dataset -->|"uses"| node_n_ds_utils
node_n_dataset -->|"configured by"| node_n_cfg_data
node_n_template -->|"composes"| node_n_encoder
node_n_template -->|"composes"| node_n_head
node_n_encoder -->|"backs"| node_n_basic_conv
node_n_encoder -->|"backs"| node_n_s4
node_n_head -->|"trains with"| node_n_losses
node_n_fm_ecg -->|"wraps"| node_n_ecg_founder
node_n_fm_ecg -->|"wraps"| node_n_ecg_cpc
node_n_fm_ecg -->|"wraps"| node_n_ecg_jepa
node_n_fm_ecg -->|"wraps"| node_n_hubert
node_n_fm_ecg -->|"wraps"| node_n_stmem
node_n_fm_ecg -->|"wraps"| node_n_merl
node_n_fm_ecg -->|"wraps"| node_n_ked
node_n_fm_ecg -->|"configured by"| node_n_cfg_run
node_n_fm_ecg -->|"configured by"| node_n_model_cfg
node_n_cauchy -.->|"accelerates"| node_n_main_lite
node_n_kernels -.->|"accelerates"| node_n_main_lite

click node_n_main_lite "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite.py"
click node_n_main_ecg "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite_ecg.py"
click node_n_main_eeg "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite_eeg.py"
click node_n_main_movement "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite_movement.py"
click node_n_pretrain "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/pretrain.py"
click node_n_dataset "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset.py"
click node_n_transforms "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset_transforms.py"
click node_n_ds_utils "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset_utils.py"
click node_n_task_ecg "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/task/ecg.py"
click node_n_template "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/template_model.py"
click node_n_encoder "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/ts/encoder.py"
click node_n_head "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/ts/head.py"
click node_n_losses "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/loss/supervised.py"
click node_n_metrics "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/metric/base.py"
click node_n_basic_conv "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/basic_conv1d.py"
click node_n_s4 "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/s4_model.py"
click node_n_xresnet "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/xresnet1d.py"
click node_n_fm_ecg "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_ecg.py"
click node_n_fm_eeg "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_eeg.py"
click node_n_fm_move "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_movement.py"
click node_n_ecg_founder "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecg_founder.py"
click node_n_ecg_cpc "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecg_cpc/basic_io.py"
click node_n_ecg_jepa "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecg_jepa/ecg_jepa.py"
click node_n_hubert "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/hubert_ecg/hubert_ecg.py"
click node_n_stmem "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/st_mem/st_mem.py"
click node_n_merl "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/merl/resnet1d.py"
click node_n_ked "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecgfm_ked.py"
click node_n_cfg_run "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/conf/config_cpc_ecg_s4_heedb.yaml"
click node_n_cfg_data "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/conf/data/ecg_heedb_S0001-1987.yaml"
click node_n_model_cfg "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/conf/data/ecg_ptbxl.yaml"
click node_n_cauchy "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/extensions/cauchy/cauchy.cpp"
click node_n_kernels "https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/extensions/kernels/setup.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_main_lite,node_n_main_ecg,node_n_main_eeg,node_n_main_movement,node_n_pretrain toneBlue
class node_n_dataset,node_n_transforms,node_n_ds_utils,node_n_task_ecg,node_n_template,node_n_encoder,node_n_head,node_n_losses,node_n_metrics toneAmber
class node_n_basic_conv,node_n_s4,node_n_xresnet,node_n_fm_ecg,node_n_fm_eeg,node_n_fm_move,node_n_ecg_founder,node_n_ecg_cpc,node_n_ecg_jepa,node_n_hubert,node_n_stmem,node_n_merl,node_n_ked toneMint
class node_n_cfg_run,node_n_cfg_data,node_n_model_cfg toneRose
class node_n_cauchy,node_n_kernels toneIndigo
```

## Components

### Entry points

Benchmark and training scripts

- [Main lite](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite.py): benchmark entry · Generic benchmark/evaluation runner · `code/main_lite.py`
- [ECG lite](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite_ecg.py): benchmark entry · ECG-specific evaluation runner · `code/main_lite_ecg.py`
- [EEG lite](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite_eeg.py): benchmark entry · EEG evaluation runner · `code/main_lite_eeg.py`
- [Move lite](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/main_lite_movement.py): benchmark entry · Movement-signal evaluation runner · `code/main_lite_movement.py`
- [Pretrain](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/pretrain.py): training entry · Pretraining workflow entry point · `code/pretrain.py`

### Clinical TS core

Shared dataset, model, task, loss, metric, and utility layers

- [Datasets](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset.py): data pipeline · Time-series dataset loading and sampling · `code/clinical_ts/data/time_series_dataset.py`
- [Transforms](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset_transforms.py): augmentation pipeline · Signal preprocessing and augmentation transforms · `code/clinical_ts/data/time_series_dataset_transforms.py`
- [Data utils](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/data/time_series_dataset_utils.py): dataset utilities · Dataset helpers and normalization/slicing utilities · `code/clinical_ts/data/time_series_dataset_utils.py`
- [ECG task](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/task/ecg.py): task orchestration · Assembles ECG benchmark experiments · `code/clinical_ts/task/ecg.py`
- [Template model](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/template_model.py): model scaffold · Reusable model construction pattern · `code/clinical_ts/template_model.py`
- [Encoder](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/ts/encoder.py): representation layer · Shared time-series encoder abstraction · `code/clinical_ts/ts/encoder.py`
- [Task head](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/ts/head.py): prediction head · Maps embeddings to outputs · `code/clinical_ts/ts/head.py`
- [Losses](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/loss/supervised.py): objective layer · Supervised and self-supervised objectives · `code/clinical_ts/loss/supervised.py`
- [Metrics](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/metric/base.py): evaluation layer · Base metrics and evaluation helpers · `code/clinical_ts/metric/base.py`

### Foundation models

ECG foundation-model adapters and model families

- [Conv1D](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/basic_conv1d.py): supervised backbone · Lightweight convolutional backbone family · `code/clinical_ts/models/basic_conv1d.py`
- [S4 family](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/s4_model.py): sequence backbone · S4-based model wrappers and modules · `code/clinical_ts/models/s4_model.py`
- [XResNet](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/xresnet1d.py): supervised backbone · 1D ResNet-style backbone · `code/clinical_ts/models/xresnet1d.py`
- [ECG FM](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_ecg.py): foundation wrapper · ECG foundation-model integration layer · `code/clinical_ts/models/fm_ecg.py`
- [EEG FM](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_eeg.py): foundation wrapper · EEG foundation-model integration layer · `code/clinical_ts/models/fm_eeg.py`
- [Move FM](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/fm_movement.py): foundation wrapper · Movement foundation-model integration layer · `code/clinical_ts/models/fm_movement.py`
- [Founder](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecg_founder.py): pretrained adapter · ECGFounder checkpoint wrapper · `code/clinical_ts/models/ecg_foundation_models/ecg_founder.py`
- [ECG CPC](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecg_cpc/basic_io.py): pretrained adapter · ECG-CPC integration and IO · `code/clinical_ts/models/ecg_foundation_models/ecg_cpc/basic_io.py`
- [ECG JEPA](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecg_jepa/ecg_jepa.py): pretrained adapter · ECG-JEPA wrapper and utilities · `code/clinical_ts/models/ecg_foundation_models/ecg_jepa/ecg_jepa.py`
- [HuBERT ECG](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/hubert_ecg/hubert_ecg.py): pretrained adapter · HuBERT-ECG integration and classification wrapper · `code/clinical_ts/models/ecg_foundation_models/hubert_ecg/hubert_ecg.py`
- [ST-MEM](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/st_mem/st_mem.py): pretrained adapter · ST-MEM integration and encoders · `code/clinical_ts/models/ecg_foundation_models/st_mem/st_mem.py`
- [MERL](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/merl/resnet1d.py): pretrained adapter · MERL backbone variants · `code/clinical_ts/models/ecg_foundation_models/merl/resnet1d.py`
- [ECGFM-KED](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/ecg_foundation_models/ecgfm_ked.py): pretrained adapter · KED-based ECGFM integration · `code/clinical_ts/models/ecg_foundation_models/ecgfm_ked.py`

### Configuration

Run and dataset configuration files

- [Run config](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/conf/config_cpc_ecg_s4_heedb.yaml): yaml config · Top-level benchmark configuration · `code/conf/config_cpc_ecg_s4_heedb.yaml`
- [Data configs](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/conf/data/ecg_heedb_S0001-1987.yaml): yaml configs · Dataset and split configuration set · `code/conf/data/ecg_heedb_S0001-1987.yaml`
- [Model cfg](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/clinical_ts/models/conf/data/ecg_ptbxl.yaml): yaml config · Model/data config namespace for clinical_ts · `code/clinical_ts/models/conf/data/ecg_ptbxl.yaml`

### Extensions

Optional performance-oriented native code

- [Cauchy](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/extensions/cauchy/cauchy.cpp): native extension · CUDA/C++ kernel package with benchmarks · `code/extensions/cauchy/cauchy.cpp`
- [Kernels](https://github.com/ai4healthuol/ecg-fm-benchmarking/blob/main/code/extensions/kernels/setup.py): native extension · Additional extension package setup · `code/extensions/kernels/setup.py`

## Connections

- Main lite → ECG task: orchestrates · Generic benchmark runner delegates task assembly
- ECG lite → ECG task: orchestrates · ECG runner assembles ECG benchmark experiments
- EEG lite → EEG FM: selects · EEG runner uses modality-specific wrappers
- Move lite → Move FM: selects · Movement runner uses modality-specific wrappers
- Pretrain → Template model: builds · Pretraining uses shared model scaffolding
- Pretrain → Losses: optimizes · Training loop applies self-supervised or supervised objectives
- ECG task → Datasets: loads · Task binds datasets into benchmark runs
- ECG task → Transforms: applies · Task uses preprocessing and augmentation
- ECG task → Metrics: reports · Task evaluates downstream performance
- Datasets → Data utils: uses · Dataset layer relies on helpers for slicing and normalization
- Datasets → Data configs: configured by · Dataset loading is driven by dataset YAMLs
- Template model → Encoder: composes · Template model wires encoder and head
- Template model → Task head: composes · Template model wires prediction head
- Encoder → Conv1D: backs · Shared encoder abstraction can host conv backbones
- Encoder → S4 family: backs · Shared encoder abstraction can host S4 backbones
- Task head → Losses: trains with · Predictions are optimized through shared loss layer
- ECG FM → Founder: wraps · ECG wrapper exposes founder checkpoint integration
- ECG FM → ECG CPC: wraps · ECG wrapper exposes CPC integration
- ECG FM → ECG JEPA: wraps · ECG wrapper exposes JEPA integration
- ECG FM → HuBERT ECG: wraps · ECG wrapper exposes HuBERT-ECG integration
- ECG FM → ST-MEM: wraps · ECG wrapper exposes ST-MEM integration
- ECG FM → MERL: wraps · ECG wrapper exposes MERL integration
- ECG FM → ECGFM-KED: wraps · ECG wrapper exposes ECGFM-KED integration
- ECG FM → Run config: configured by · Runs are driven by top-level YAML config
- ECG FM → Model cfg: configured by · Model wrappers consume shared model/data config
- Cauchy → Main lite: accelerates · Optional native compute acceleration for experiments
- Kernels → Main lite: accelerates · Optional kernel package supports training/eval performance
