# sparkzu/radiollm architecture

> Architecture diagram of the GitHub repository sparkzu/radiollm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sparkzu/radiollm
- Repository: https://github.com/sparkzu/radiollm

## Overview

##### Project Type and Purpose
- RadioLLM is an ML research framework rather than a user-facing application. It integrates Hybrid Prompt and Token Reprogramming (HPTR) and a Frequency Attuned Fusion (FAF) module into large language models for cognitive radio signal processing tasks.
- Key use cases: pretraining on radio‐signal datasets, fine-tuning with expert prompts, and benchmarking on CRT (cognitive radio tasks).

##### Main Components
a. Data Layer
- dataset.py: orchestrates loading of benchmark datasets (e.g., from Hugging Face).
- utils/sig_utils.py & utils/signal_aug.py: domain‐specific signal processing and augmentation routines.
b. Model Layer
- model/embed.py: transforms raw or augmented signals into token embeddings suitable for LLM input.
- model/radiollm.py: core RadioLLM class implementing HPTR and FAF modules on top of a base Transformer.
- model/norm.py & model/utils.py: normalization layers and shared helper functions used by the model.
c. Training Pipelines
- pretrain.py: runs unsupervised or multi-task pretraining (configurable via script/multi_task_pretrain.yaml).
- finetune.py: script for supervised fine-tuning on downstream CRT tasks.
- script/multi_task_pretrain.yaml: YAML config defining datasets, hyperparameters, and task splits.
d. Deployment & Environment
- Dockerfile: containerizes Python 3.9 environment, PyTorch, Hugging Face Transformers & PEFT.
- README.md & docs/: documentation and assets (logo, high‐level usage).

##### Relationships and Data Flow
- Dataset inputs → (sig_utils + signal_aug) → dataset.py batches → embed module → core RadiollM model (HPTR + FAF) → loss computation → optimizer → updated model weights.
- pretrain.py and finetune.py drive above pipeline, loading the correct config, invoking dataset pipelines, instantiating the model, and logging metrics.
- External libraries (PyTorch, Transformers, PEFT) are dependencies used throughout model and training scripts.

##### Architectural Patterns & Principles
- Modular separation: data processing, model definition, and training logic kept in separate directories/files.
- Configuration-driven experiments: YAML file for hyperparameters & task definitions.
- Reusable utilities: common signal and model helpers in `utils/` and `model/utils.py`.
- Containerization: Docker ensures reproducible environment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Docker Container" 
        style DockerContainer stroke:#333,stroke-width:4px

        %% Data Layer
        subgraph "Data Layer"
            direction TB
            Datasets["Benchmark Datasets"]:::external
            HF["Hugging Face Datasets"]:::external
            SigUtils["sig_utils.py"]:::code
            SignalAug["signal_aug.py"]:::code
            DatasetLoader["dataset.py"]:::code

            Datasets -->|"raw signal"| SigUtils
            HF -->|"raw signal"| SigUtils
            SigUtils -->|"processed signal"| SignalAug
            SignalAug -->|"augmented signal"| DatasetLoader
            click SigUtils "https://github.com/sparkzu/radiollm/blob/main/utils/sig_utils.py"
            click SignalAug "https://github.com/sparkzu/radiollm/blob/main/utils/signal_aug.py"
            click DatasetLoader "https://github.com/sparkzu/radiollm/blob/main/dataset.py"
        end

        %% Model Layer
        subgraph "Model Layer"
            direction TB
            Embed["embed.py"]:::code
            Norm["norm.py"]:::code
            ModelUtils["utils.py"]:::code

            subgraph "RadioLLM (radiollm.py)"
                style RadioLLM stroke:#228B22,stroke-width:2px
                HPTR["HPTR Module"]:::code
                FAF["FAF Module"]:::code
            end

            DatasetLoader -->|"signal tokens"| Embed
            Embed --> RadioLLM
            RadioLLM --> Norm
            RadioLLM --> ModelUtils

            click Embed "https://github.com/sparkzu/radiollm/blob/main/model/embed.py"
            click RadioLLM "https://github.com/sparkzu/radiollm/blob/main/model/radiollm.py"
            click Norm "https://github.com/sparkzu/radiollm/blob/main/model/norm.py"
            click ModelUtils "https://github.com/sparkzu/radiollm/blob/main/model/utils.py"
        end

        %% Training Pipelines
        subgraph "Training"
            direction TB
            Pretrain["pretrain.py"]:::code
            Finetune["finetune.py"]:::code
            Config["multi_task_pretrain.yaml"]:::config

            Pretrain -->|runs pipeline| DatasetLoader
            Pretrain -->|instantiates model| RadioLLM
            Finetune -->|runs pipeline| DatasetLoader
            Finetune -->|instantiates model| RadioLLM
            Config -.->|configures| Pretrain
            Config -.->|configures| Finetune

            click Pretrain "https://github.com/sparkzu/radiollm/blob/main/pretrain.py"
            click Finetune "https://github.com/sparkzu/radiollm/blob/main/finetune.py"
            click Config "https://github.com/sparkzu/radiollm/blob/main/script/multi_task_pretrain.yaml"
        end

        %% Dependencies and Logging
        subgraph "Dependencies & Logging"
            direction TB
            PT["PyTorch"]:::external
            HFTrans["Transformers"]:::external
            PEFT["PEFT"]:::external
            Logs["Metrics & Logging"]:::code

            Pretrain --> PT
            Pretrain --> HFTrans
            Pretrain --> PEFT
            Finetune --> PT
            Finetune --> HFTrans
            Finetune --> PEFT

            RadioLLM --> Logs
        end

        %% Documentation
        subgraph "Documentation"
            direction TB
            Readme["README.md"]:::doc
            Docs["docs/"]:::doc
            Readme --> Docs
            click Readme "https://github.com/sparkzu/radiollm/blob/main/README.md"
            click Docs "https://github.com/sparkzu/radiollm/tree/main/docs/"
        end

    end

    classDef code fill:#e0f7e9,stroke:#228B22,stroke-width:1px
    classDef external fill:#ffedd5,stroke:#e07c24,stroke-width:1px,stroke-dasharray: 5 5
    classDef config fill:#d0e7ff,stroke:#339af0,stroke-width:1px,stroke-dasharray: 3 3
    classDef doc fill:#f0f0f0,stroke:#999,stroke-width:1px,stroke-dasharray: 2 2
    class DockerContainer external
```
