# shazzad5709/chrysalis architecture

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

- Interactive diagram: https://gitdiagram.com/shazzad5709/chrysalis
- Repository: https://github.com/shazzad5709/chrysalis

## Overview

1. **What this repository is**
   Chrysalis is a Python-based behavioral regression testing framework for NLP models. The core idea is: define behavior tests as reusable “MRs” (test relations/specs), generate a validated corpus for each MR, snapshot model behavior for different model versions, then diff those snapshots to detect regressions.

2. **Core library boundary**
   The `chrysalis/` package is the reusable engine. Everything under `pilot/` is orchestration, experiments, and artifact production. In architecture terms, `chrysalis` is the library layer; `pilot` is the application/workflow layer that wires models, datasets, and runs together.

3. **MR definitions and registry**
   `chrysalis/mrs/` contains the individual behavioral test definitions, grouped by domain:
   - `generic/` for generic generation tests
   - `nli/` for natural language inference
   - `sa/` for sentiment analysis  
   `chrysalis/registry/mr_registry.yaml` and `registry.py` provide the lookup layer that maps MR IDs like `CHR-GEN-005` or `CHR-NLI-004` to their implementation classes. This registry is the main entry point for discovering which behaviors are available.

4. **Corpus generation pipeline**
   `chrysalis/corpus/generator.py`, `schemas.py`, and `validator.py` form the corpus-building subsystem. Their job is to turn MR definitions into CSV corpora, validate the generated items, and track rejected candidates. The artifacts in `pilot/.../corpus/` show the outputs of this stage: per-MR corpus CSVs, a `corpus_manifest.json`, and `rejection_log.csv`.

5. **Snapshotting and regression detection**
   `chrysalis/snapshot/engine.py` captures model outputs over a corpus for a specific model version or configuration. `chrysalis/regression/differ.py` compares two snapshot sets and produces regression reports. This is the key data-flow boundary in the system: same corpus in, versioned snapshot outputs out, then pairwise diff between versions.

6. **Versioned model lifecycle**
   The `pilot/artifacts/*/snapshots/` directories show the system’s model lifecycle across versions such as `v1_base`, `v2_retrain`, `v3_distilled`, and `v4_quantized`. Each version has snapshot CSVs per MR. This implies the regression engine is version-aware and intended to support iterative model development, not just one-off evaluation.

7. **Pilot orchestration layer**
   `pilot/pipeline.py` appears to coordinate end-to-end execution across corpus generation, manual validation, snapshotting, and regression comparison. `pilot/model_loader.py` and `pilot/quantized_model_loader.py` isolate model loading concerns, while `pilot/quantize_v4.py` represents a dedicated quantization workflow for the final model stage.

8. **Training and benchmark workflows**
   `pilot/training/train_v1.py`, `train_v2.py`, and `train_v3.py` indicate distinct training pipelines for successive model versions. `pilot/benchmark_gpu.py` and `benchmark_gpu.sh` suggest GPU-backed evaluation/benchmarking is part of the workflow, especially for performance-sensitive or quantized model runs.

9. **Profiles and datasets**
   The artifact structure shows the same pipeline applied across multiple task/dataset profiles: `gen_agnews`, `gen_imdb`, `gen_multinli`, `gen_snli`, `gen_sst2`, `nli_multinli`, `nli_snli`, `sa_imdb`, `sa_sst2`. This indicates the framework is profile-driven: the same engine is reused with different task families and dataset-specific corpora.

10. **Human-in-the-loop validation**
    The `manual_validation/` artifacts show an intermediate review step between corpus generation and snapshotting. That means the pipeline is not fully automatic: generated test cases are reviewed or curated before being used as the final regression corpus. This is an important architectural boundary for diagramming the workflow.

11. **Test strategy**
    `tests/unit/` contains MR-specific unit tests for each behavior definition, and `tests/integration/test_corpus_pipeline.py` validates the corpus pipeline end to end. This mirrors the architecture: behavior modules are tested individually, and the corpus generation flow is tested as a system.

12. **Tooling and runtime**
    The repo is a Python project managed with `uv` (`pyproject.toml`, `uv.lock`, `requirements.txt`). The README calls out `spacy` model download and `nltk` word data, which are material dependencies for text processing and corpus generation. That matters architecturally because the corpus layer depends on NLP runtime assets, not just Python code.

13. **Pre-generated artifacts as reference outputs**
    The large `pilot/artifacts/` and `pilot/test_artifacts/` trees are not just logs; they are reference outputs for demos, regression comparisons, and tests. They document expected data products at each stage: corpus, manual validation, snapshot, and regression report. For an architecture diagram, these should be shown as outputs of the pilot workflow rather than part of the library itself.

Main entry points: [`chrysalis/mrs`](https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs) (MRs), [`pilot/pipeline.py`](https://github.com/shazzad5709/chrysalis/blob/main/pilot/pipeline.py) (Pipeline), [`pilot/artifacts`](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts) (Profiles), [`pilot/artifacts/gen_agnews/manual_validation`](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/manual_validation) (Manual review)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_chrysalis["chrysalis library"]
  node_node_mrs["MRs<br/>behavior specs"]
  node_node_registry["Registry<br/>MR lookup<br/>[registry.py]"]
  node_node_corpus["Corpus builder<br/>validation pipeline<br/>[generator.py]"]
  node_node_snapshot["Snapshot engine<br/>model capture<br/>[engine.py]"]
  node_node_regression["Diff engine<br/>snapshot compare<br/>[differ.py]"]
  node_node_base["Base MR<br/>MR base class<br/>[base.py]"]
  node_node_generic["Generic MRs<br/>generation domain"]
  node_node_nli["NLI MRs<br/>inference domain"]
  node_node_sa["SA MRs<br/>sentiment domain"]
end

subgraph group_group_pilot["pilot workflows"]
  node_node_pipeline["Pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_node_loader["Model loader<br/>model IO<br/>[model_loader.py]"]
  node_node_qloader["Quantized loader<br/>model IO"]
  node_node_train["Training"]
  node_node_quant["Quantize v4<br/>compression workflow<br/>[quantize_v4.py]"]
  node_node_bench["GPU bench<br/>benchmarking<br/>[benchmark_gpu.py]"]
end

subgraph group_group_artifacts["reference artifacts"]
  node_node_profiles["Profiles<br/>artifact sets"]
  node_node_corpus_out["Corpus outputs<br/>artifact stage"]
  node_node_validation["Manual review<br/>human-in-loop"]
  node_node_snapshots["Snapshots<br/>versioned outputs"]
  node_node_reports["Regression reports<br/>diff outputs"]
end

subgraph group_group_tests["tests"]
  node_node_unit["MR tests<br/>unit coverage"]
  node_node_integration["Pipeline test<br/>integration coverage"]
end

node_node_mrs -->|"extends"| node_node_base
node_node_generic -->|"contains"| node_node_mrs
node_node_nli -->|"contains"| node_node_mrs
node_node_sa -->|"contains"| node_node_mrs
node_node_registry -->|"resolves"| node_node_mrs
node_node_corpus -->|"builds from"| node_node_mrs
node_node_pipeline -->|"runs"| node_node_corpus
node_node_pipeline -->|"includes"| node_node_validation
node_node_pipeline -->|"runs"| node_node_snapshot
node_node_pipeline -->|"runs"| node_node_regression
node_node_loader -->|"feeds"| node_node_pipeline
node_node_qloader -->|"feeds"| node_node_quant
node_node_train -->|"produces"| node_node_loader
node_node_quant -->|"produces"| node_node_qloader
node_node_bench -->|"uses"| node_node_qloader
node_node_profiles -->|"stores"| node_node_corpus_out
node_node_profiles -->|"stores"| node_node_validation
node_node_profiles -->|"stores"| node_node_snapshots
node_node_profiles -->|"stores"| node_node_reports
node_node_unit -->|"covers"| node_node_mrs
node_node_integration -->|"covers"| node_node_pipeline
node_node_corpus_out -->|"refines into"| node_node_validation
node_node_validation -->|"enables"| node_node_snapshots
node_node_snapshot -->|"diffs into"| node_node_reports

click node_node_mrs "https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs"
click node_node_registry "https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/registry/registry.py"
click node_node_corpus "https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/corpus/generator.py"
click node_node_snapshot "https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/snapshot/engine.py"
click node_node_regression "https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/regression/differ.py"
click node_node_base "https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/mrs/base.py"
click node_node_generic "https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs/generic"
click node_node_nli "https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs/nli"
click node_node_sa "https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs/sa"
click node_node_pipeline "https://github.com/shazzad5709/chrysalis/blob/main/pilot/pipeline.py"
click node_node_loader "https://github.com/shazzad5709/chrysalis/blob/main/pilot/model_loader.py"
click node_node_qloader "https://github.com/shazzad5709/chrysalis/blob/main/pilot/quantized_model_loader.py"
click node_node_train "https://github.com/shazzad5709/chrysalis/tree/main/pilot/training"
click node_node_quant "https://github.com/shazzad5709/chrysalis/blob/main/pilot/quantize_v4.py"
click node_node_bench "https://github.com/shazzad5709/chrysalis/blob/main/pilot/benchmark_gpu.py"
click node_node_profiles "https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts"
click node_node_corpus_out "https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/corpus"
click node_node_validation "https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/manual_validation"
click node_node_snapshots "https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/snapshots"
click node_node_reports "https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/regression_reports"
click node_node_unit "https://github.com/shazzad5709/chrysalis/tree/main/tests/unit"
click node_node_integration "https://github.com/shazzad5709/chrysalis/blob/main/tests/integration/test_corpus_pipeline.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_node_mrs,node_node_registry,node_node_corpus,node_node_snapshot,node_node_regression,node_node_base,node_node_generic,node_node_nli,node_node_sa toneBlue
class node_node_pipeline,node_node_loader,node_node_qloader,node_node_train,node_node_quant,node_node_bench toneAmber
class node_node_profiles,node_node_corpus_out,node_node_validation,node_node_snapshots,node_node_reports toneMint
class node_node_unit,node_node_integration toneRose
```

## Components

### chrysalis library

Reusable engine for MR definitions, corpus generation, snapshotting, and regression diffs.

- [MRs](https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs): behavior specs · Behavioral regression test relations grouped by domain. · `chrysalis/mrs`
- [Registry](https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/registry/registry.py): MR lookup · Maps MR IDs to implementation classes. · `chrysalis/registry/registry.py`
- [Corpus builder](https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/corpus/generator.py): validation pipeline · Generates, validates, and tracks rejected corpus candidates. · `chrysalis/corpus/generator.py`
- [Snapshot engine](https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/snapshot/engine.py): model capture · Runs a model over a corpus and stores versioned outputs. · `chrysalis/snapshot/engine.py`
- [Diff engine](https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/regression/differ.py): snapshot compare · Compares snapshot sets and produces regression reports. · `chrysalis/regression/differ.py`
- [Base MR](https://github.com/shazzad5709/chrysalis/blob/main/chrysalis/mrs/base.py): MR base class · Shared abstractions for MR implementations. · `chrysalis/mrs/base.py`
- [Generic MRs](https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs/generic): generation domain · Generic generation behavior specs. · `chrysalis/mrs/generic`
- [NLI MRs](https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs/nli): inference domain · Natural language inference behavior specs. · `chrysalis/mrs/nli`
- [SA MRs](https://github.com/shazzad5709/chrysalis/tree/main/chrysalis/mrs/sa): sentiment domain · Sentiment analysis behavior specs. · `chrysalis/mrs/sa`

### pilot workflows

Orchestration layer that runs training, quantization, end-to-end pipelines, and produces artifacts.

- [Pipeline](https://github.com/shazzad5709/chrysalis/blob/main/pilot/pipeline.py): orchestrator · Coordinates corpus generation, validation, snapshotting, and regression comparison. · `pilot/pipeline.py`
- [Model loader](https://github.com/shazzad5709/chrysalis/blob/main/pilot/model_loader.py): model IO · Loads non-quantized model variants for runs and evaluation. · `pilot/model_loader.py`
- [Quantized loader](https://github.com/shazzad5709/chrysalis/blob/main/pilot/quantized_model_loader.py): model IO · Loads quantized model variants. · `pilot/quantized_model_loader.py`
- [Training](https://github.com/shazzad5709/chrysalis/tree/main/pilot/training): versioned training · Successive training workflows for model versions v1 through v3. · `pilot/training`
- [Quantize v4](https://github.com/shazzad5709/chrysalis/blob/main/pilot/quantize_v4.py): compression workflow · Dedicated workflow for producing the v4 quantized model. · `pilot/quantize_v4.py`
- [GPU bench](https://github.com/shazzad5709/chrysalis/blob/main/pilot/benchmark_gpu.py): benchmarking · GPU-backed evaluation and benchmarking entry point. · `pilot/benchmark_gpu.py`

### reference artifacts

Pre-generated corpus, validation, snapshot, and report outputs used as workflow references.

- [Profiles](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts): artifact sets · Task/dataset profiles that reuse the same pipeline across domains. · `pilot/artifacts`
- [Corpus outputs](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/corpus): artifact stage · Per-MR corpus CSVs, manifests, and rejection logs. · `pilot/artifacts/gen_agnews/corpus`
- [Manual review](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/manual_validation): human-in-loop · Intermediate validation artifacts between corpus generation and snapshotting. · `pilot/artifacts/gen_agnews/manual_validation`
- [Snapshots](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/snapshots): versioned outputs · Model outputs captured per profile and model version. · `pilot/artifacts/gen_agnews/snapshots`
- [Regression reports](https://github.com/shazzad5709/chrysalis/tree/main/pilot/artifacts/gen_agnews/regression_reports): diff outputs · Pairwise regression comparisons across model versions. · `pilot/artifacts/gen_agnews/regression_reports`

### tests

Unit and integration coverage for MR logic and the corpus pipeline.

- [MR tests](https://github.com/shazzad5709/chrysalis/tree/main/tests/unit): unit coverage · Unit tests for individual MR definitions. · `tests/unit`
- [Pipeline test](https://github.com/shazzad5709/chrysalis/blob/main/tests/integration/test_corpus_pipeline.py): integration coverage · End-to-end corpus pipeline validation. · `tests/integration/test_corpus_pipeline.py`

## Connections

- MRs → Base MR: extends · MR implementations share a common base.
- Generic MRs → MRs: contains · Generic domain MR implementations.
- NLI MRs → MRs: contains · NLI domain MR implementations.
- SA MRs → MRs: contains · Sentiment analysis MR implementations.
- Registry → MRs: resolves · Registry maps MR IDs to classes.
- Corpus builder → MRs: builds from · Corpus generation starts from MR definitions.
- Pipeline → Corpus builder: runs · Pilot coordinates corpus generation.
- Pipeline → Manual review: includes · Manual validation is part of the workflow.
- Pipeline → Snapshot engine: runs · Pilot snapshots model outputs after validation.
- Pipeline → Diff engine: runs · Pilot compares snapshot versions.
- Model loader → Pipeline: feeds · Model loading supports the orchestration layer.
- Quantized loader → Quantize v4: feeds · Quantized model loading supports v4 quantization runs.
- Training → Model loader: produces · Training workflows yield model versions for loading.
- Quantize v4 → Quantized loader: produces · Quantization yields quantized model variants.
- GPU bench → Quantized loader: uses · Benchmarking evaluates quantized or specialized models.
- Profiles → Corpus outputs: stores · Profiles materialize corpus artifacts.
- Profiles → Manual review: stores · Profiles materialize manual validation artifacts.
- Profiles → Snapshots: stores · Profiles materialize versioned snapshots.
- Profiles → Regression reports: stores · Profiles materialize regression reports.
- MR tests → MRs: covers · Unit tests exercise individual MR implementations.
- Pipeline test → Pipeline: covers · Integration test validates the corpus pipeline.
- Corpus outputs → Manual review: refines into · Generated corpus is reviewed before use.
- Manual review → Snapshots: enables · Validated corpus feeds snapshotting.
- Snapshot engine → Regression reports: diffs into · Snapshot sets are compared into regression reports.
