# castlechen339/dehazexl architecture

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

- Interactive diagram: https://gitdiagram.com/castlechen339/dehazexl
- Repository: https://github.com/castlechen339/dehazexl

## Overview

DehazeXL is a large-image haze-removal research implementation. Its main workflows are paired-image training on 8KDehaze and checkpoint-based inference on a hazy image; the README also documents global-context processing and attribution-map evaluation. The sampled decoder and training code establish the training/model connections, while test.py and several context modules were not sampled, so their internal wiring is not asserted.

Main entry points: [`models/DehazeXL/decoders/decoder.py`](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/decoder.py) (DehazeXL), [`train.py`](https://github.com/castlechen339/dehazexl/blob/main/train.py) (Training and Evaluation), [`models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py`](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py) (HyperAttention), [`test.py`](https://github.com/castlechen339/dehazexl/blob/main/test.py) (Image Testing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Haze Data"]
  node_dataset["Paired Haze Dataset<br/>[dataset.py]"]
end

subgraph group_model["DehazeXL Model"]
  node_dehazexl["DehazeXL<br/>[decoder.py]"]
  node_swin["SwinV2 Backbone<br/>[swin.py]"]
  node_swin_decoder["Swin Decoder<br/>[decoder.py]"]
  node_decoder_utils["Decoder Utilities<br/>[utils.py]"]
end

subgraph group_context["Global Context"]
  node_context_config["Context Configuration<br/>[__init__.py]"]
  node_transformer_xl["Transformer-XL Context<br/>[transformer_xl.py]"]
  node_llm_attention["LLM Attention<br/>[attention.py]"]
  node_attention_mla["Attention MLA<br/>[attentionmla.py]"]
  node_hyper_attention["HyperAttention<br/>[hyper_attn.py]"]
  node_angular_lsh["Angular LSH<br/>[angular_lsh.py]"]
  node_attention_utils["Attention Utilities<br/>[utils.py]"]
  node_flash_kernel["Flash Attention Kernel"]
  node_attention_adapter["ChatGLM Attention Adapter"]
  node_attention_replacement["LLM Attention Replacement"]
end

subgraph group_run["Training and Inference"]
  node_trainer["Training and Evaluation<br/>[train.py]"]
  node_inference["Image Testing<br/>[test.py]"]
  node_checkpoint["Model Checkpoint"]
end

node_researcher(("Researcher"))

node_researcher -->|"starts training"| node_trainer
node_researcher -->|"tests image"| node_inference
node_trainer -->|"loads pairs"| node_dataset
node_trainer -->|"trains model"| node_dehazexl
node_trainer -->|"saves weights"| node_checkpoint
node_inference -->|"loads weights"| node_checkpoint
node_inference -->|"runs inference"| node_dehazexl
node_dehazexl -->|"uses backbone"| node_swin
node_dehazexl -.->|"decodes features"| node_swin_decoder
node_dehazexl -->|"configures context"| node_context_config
node_dehazexl -->|"uses attention"| node_llm_attention
node_dehazexl -->|"uses utilities"| node_decoder_utils
node_context_config -.->|"selects context"| node_transformer_xl
node_llm_attention -->|"delegates attention"| node_hyper_attention
node_hyper_attention -->|"hashes tokens"| node_angular_lsh
node_hyper_attention -->|"uses helpers"| node_attention_utils

click node_dataset "https://github.com/castlechen339/dehazexl/blob/main/dataset.py"
click node_trainer "https://github.com/castlechen339/dehazexl/blob/main/train.py"
click node_inference "https://github.com/castlechen339/dehazexl/blob/main/test.py"
click node_dehazexl "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/decoder.py"
click node_swin "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/backbones/swin.py"
click node_swin_decoder "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/decoder.py"
click node_decoder_utils "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/utils.py"
click node_context_config "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/__init__.py"
click node_transformer_xl "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/transformer_xl.py"
click node_llm_attention "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/attention.py"
click node_attention_mla "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/attentionmla.py"
click node_hyper_attention "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py"
click node_angular_lsh "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/angular_lsh.py"
click node_attention_utils "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/utils.py"
click node_flash_kernel "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/flash_attn_triton_for_hyper.py"
click node_attention_adapter "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/modeling_chatglm_fast_attention.py"
click node_attention_replacement "https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/replace_llm_attention.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_dataset toneBlue
class node_dehazexl,node_swin,node_swin_decoder,node_decoder_utils toneAmber
class node_context_config,node_transformer_xl,node_llm_attention,node_attention_mla,node_hyper_attention,node_angular_lsh,node_attention_utils,node_flash_kernel,node_attention_adapter,node_attention_replacement toneMint
class node_trainer,node_inference,node_checkpoint toneRose
class node_researcher toneIndigo
```

## Components

### Haze Data

- [Paired Haze Dataset](https://github.com/castlechen339/dehazexl/blob/main/dataset.py): `dataset.py`

### DehazeXL Model

- [DehazeXL](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/decoder.py): `models/DehazeXL/decoders/decoder.py`
- [SwinV2 Backbone](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/backbones/swin.py): `models/DehazeXL/backbones/swin.py`
- [Swin Decoder](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/decoder.py): `models/DehazeXL/decoders/decoder.py`
- [Decoder Utilities](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/decoders/utils.py): `models/DehazeXL/decoders/utils.py`

### Global Context

- [Context Configuration](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/__init__.py): `models/DehazeXL/context_encoders/__init__.py`
- [Transformer-XL Context](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/transformer_xl.py): `models/DehazeXL/context_encoders/transformer_xl.py`
- [LLM Attention](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/attention.py): `models/DehazeXL/context_encoders/attention.py`
- [Attention MLA](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/attentionmla.py): `models/DehazeXL/context_encoders/attentionmla.py`
- [HyperAttention](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py): `models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py`
- [Angular LSH](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/angular_lsh.py): `models/DehazeXL/context_encoders/hyper_attn/attention/angular_lsh.py`
- [Attention Utilities](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/utils.py): `models/DehazeXL/context_encoders/hyper_attn/attention/utils.py`
- [Flash Attention Kernel](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/flash_attn_triton_for_hyper.py): `models/DehazeXL/context_encoders/hyper_attn/attention/flash_attn_triton_for_hyper.py`
- [ChatGLM Attention Adapter](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/attention/modeling_chatglm_fast_attention.py): `models/DehazeXL/context_encoders/hyper_attn/attention/modeling_chatglm_fast_attention.py`
- [LLM Attention Replacement](https://github.com/castlechen339/dehazexl/blob/main/models/DehazeXL/context_encoders/hyper_attn/replace_llm_attention.py): `models/DehazeXL/context_encoders/hyper_attn/replace_llm_attention.py`

### Training and Inference

- [Training and Evaluation](https://github.com/castlechen339/dehazexl/blob/main/train.py): `train.py`
- [Image Testing](https://github.com/castlechen339/dehazexl/blob/main/test.py): `test.py`
- **Model Checkpoint**

### Other components

- **Researcher**

## Connections

- Researcher → Training and Evaluation: starts training (evidence: `README.md`)
- Researcher → Image Testing: tests image (evidence: `README.md`)
- Training and Evaluation → Paired Haze Dataset: loads pairs (evidence: `train.py`)
- Training and Evaluation → DehazeXL: trains model (evidence: `train.py`)
- Training and Evaluation → Model Checkpoint: saves weights (evidence: `train.py`)
- Image Testing → Model Checkpoint: loads weights (evidence: `README.md`)
- Image Testing → DehazeXL: runs inference (evidence: `README.md`)
- DehazeXL → SwinV2 Backbone: uses backbone (evidence: `models/DehazeXL/decoders/decoder.py`)
- DehazeXL → Swin Decoder: decodes features (evidence: `models/DehazeXL/decoders/decoder.py`)
- DehazeXL → Context Configuration: configures context (evidence: `models/DehazeXL/decoders/decoder.py`)
- DehazeXL → LLM Attention: uses attention (evidence: `models/DehazeXL/decoders/decoder.py`)
- DehazeXL → Decoder Utilities: uses utilities (evidence: `models/DehazeXL/decoders/decoder.py`)
- Context Configuration → Transformer-XL Context: selects context
- LLM Attention → HyperAttention: delegates attention (evidence: `models/DehazeXL/context_encoders/attention.py`)
- HyperAttention → Angular LSH: hashes tokens (evidence: `models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py`)
- HyperAttention → Attention Utilities: uses helpers (evidence: `models/DehazeXL/context_encoders/hyper_attn/attention/hyper_attn.py`)
