How shazzad5709/chrysalis works
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: mrs MRs · pipeline.py Pipeline · artifacts Profiles · manual_validation Manual review
Components 22
chrysalis library
Reusable engine for MR definitions, corpus generation, snapshotting, and regression diffs.
- MRs · Behavioral regression test relations grouped by domain.
chrysalis/mrs - Registry · Maps MR IDs to implementation classes.
chrysalis/registry/registry.py - Corpus builder · Generates, validates, and tracks rejected corpus candidates.
chrysalis/corpus/generator.py - Snapshot engine · Runs a model over a corpus and stores versioned outputs.
chrysalis/snapshot/engine.py - Diff engine · Compares snapshot sets and produces regression reports.
chrysalis/regression/differ.py - Base MR · Shared abstractions for MR implementations.
chrysalis/mrs/base.py - Generic MRs · Generic generation behavior specs.
chrysalis/mrs/generic - NLI MRs · Natural language inference behavior specs.
chrysalis/mrs/nli - SA MRs · Sentiment analysis behavior specs.
chrysalis/mrs/sa
pilot workflows
Orchestration layer that runs training, quantization, end-to-end pipelines, and produces artifacts.
- Pipeline · Coordinates corpus generation, validation, snapshotting, and regression comparison.
pilot/pipeline.py - Model loader · Loads non-quantized model variants for runs and evaluation.
pilot/model_loader.py - Quantized loader · Loads quantized model variants.
pilot/quantized_model_loader.py - Training · Successive training workflows for model versions v1 through v3.
pilot/training - Quantize v4 · Dedicated workflow for producing the v4 quantized model.
pilot/quantize_v4.py - GPU bench · 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 · Task/dataset profiles that reuse the same pipeline across domains.
pilot/artifacts - Corpus outputs · Per-MR corpus CSVs, manifests, and rejection logs.
pilot/artifacts/gen_agnews/corpus - Manual review · Intermediate validation artifacts between corpus generation and snapshotting.
pilot/artifacts/gen_agnews/manual_validation - Snapshots · Model outputs captured per profile and model version.
pilot/artifacts/gen_agnews/snapshots - Regression reports · 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 · Unit tests for individual MR definitions.
tests/unit - Pipeline test · End-to-end corpus pipeline validation.
tests/integration/test_corpus_pipeline.py
Connections 24
- 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.