Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 44 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,49 @@ jobs:
- name: Install locked dependencies
run: uv sync --locked --extra legacy-ui

- name: Lint supported architecture boundary
run: >-
uv run ruff check
src/blueprinting/__init__.py
src/blueprinting/__main__.py
src/blueprinting/cli
src/blueprinting/schema
src/blueprinting/workload
src/blueprinting/mapping
src/blueprinting/system
src/blueprinting/synthesizer
src/blueprinting/analysis
src/blueprinting/validation
src/blueprinting/application
src/blueprinting/workbench
tests/synthesizer
tests/analysis
tests/application
tests/regression
tests/workbench

- name: Run tests
run: uv run pytest

package-contract:
name: Base wheel contract
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true

- name: Install Python
run: uv python install 3.12

- name: Build wheel
run: uv build --wheel

- name: Verify wheel contents and size
run: uv run python scripts/check_wheel_contract.py dist/*.whl
20 changes: 16 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Pass pipeline 依据声明式 contract 编排,不得依赖具体 Python pass

Binding 分为独立维度:workload、strategy、target、deployment、calibration。

- workload/strategy 可以逐步特化,但必须显式记录在 typed derivation context;当前代码名为 `CompilationSession`;
- workload/strategy 可以逐步特化,但必须显式记录在 typed derivation context;当前代码名为 `SynthesisSession`;
- target/deployment 只能在 portable plan 之后进入;
- 同一个 `PortablePlanIR` 必须能绑定到多个实质不同的硬件目标;
- target 变化不得改变 `ModelIR`、`DistributedTaskIR` 或 `PortablePlanIR` digest;
Expand Down Expand Up @@ -142,12 +142,18 @@ handling。若 LPU 的 issue cycle/slot 具有 correctness 含义,它在 targe

## 9. 当前实现边界

当前形式化分析实现仍位于历史 package path `src/blueprinting/compiler/`。该路径为兼容性保留,不定义产品架构。已经实现:
无领域依赖的 codec 与 immutable schema primitive 位于 `src/blueprinting/schema/`;target-neutral workload contract
位于 `src/blueprinting/workload/`,逻辑策略与显式 deployment mapping 位于 `src/blueprinting/mapping/`,芯片、memory、
interconnect 与 system profile 位于 `src/blueprinting/system/`;canonical 表示与形式化推导机制位于
`src/blueprinting/synthesizer/`,分析与证据评估位于同级 `src/blueprinting/analysis/`,外部 baseline 与回归 gate
位于 `src/blueprinting/validation/`。Synthesizer 表示 formal plan synthesis 的实现边界,不是产品身份、RTL 综合器
或独立 Compiler 组件。已经实现:

- 五层 canonical IR 的 immutable schema、serialization 和 structural verifier;其中后两层仍是 experimental contract;
- stable ID、lineage、typed scalar expression、binding/session;
- pass contract、analysis cache/invalidation 和 derivation checkpoint;
- decoder-only Transformer training frontend;
- decoder-only Transformer workload contract 与 training/inference frontend adapter;
- compute、memory、interconnect 和聚合 `SystemProfile` contract;
- `ModelIR -> DistributedTaskIR -> PortablePlanIR` 的 TP、recompute、workload 与 buffer derivation;
- peak-only / system-evidence cost view 和 Calculon/SeqSel 校准实验。

Expand All @@ -162,7 +168,13 @@ handling。若 LPU 的 issue cycle/slot 具有 correctness 含义,它在 targe

## 10. 代码与仓库规则

- 新形式化表示、推导与分析代码在 package 重命名 ADR 通过前进入 `src/blueprinting/compiler/` 对应边界;不得新建平行表示栈。
- 无领域依赖的 canonical codec、frozen value 与 schema error 进入 `src/blueprinting/schema/`;workload semantic/request contract 进入 `src/blueprinting/workload/`;逻辑 strategy 与 deployment mapping 进入
`src/blueprinting/mapping/`;芯片、memory、interconnect 与 system contract 进入 `src/blueprinting/system/`;workload-to-IR adapter、canonical 表示与推导进入
`src/blueprinting/synthesizer/`;cost/evidence analysis 进入 `src/blueprinting/analysis/`。不得新建平行表示栈。
- `SystemProfile` 是当前有限的 compute/memory/network evidence-bearing adapter,不得被描述成已经实现的完整
`ArchitectureBlueprint`;`src/blueprinting/types/system/` 只服务 legacy calculator,新代码不得依赖它。
- `blueprinting.compiler` Python path 已硬切删除;历史 `compiler.*` canonical codec tag 作为 wire identity 保留,
未经迁移 ADR 不得改写。
- IR 对象默认 frozen;语义字段使用 typed dataclass/enum/ID,不使用自由字典代替 contract。
- 所有公共 derivation/transformation 和 verifier 必须有 positive、negative、round-trip 与 lineage 测试。
- Python 最低版本为 3.10;不得使用只在更高版本解析的语法,除非先更新 packaging contract。
Expand Down
62 changes: 30 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ provides:
- immutable schemas and structural verifiers for the current five-layer IR backbone; only the first three layers have a production derivation slice, while `ConcretePlanIR` and `MachineIR` remain experimental contracts;
- stable IDs, lineage, schema-versioned serialization, content digests, and typed binding sessions;
- declarative transformation contracts with analysis invalidation and derivation checkpoints;
- a typed decoder-only Transformer training frontend;
- `ModelIR -> DistributedTaskIR -> PortablePlanIR` staged derivation with explicit TP collectives, recomputation, workload,
and buffer facts;
- peak-only and hardware-evidence cost views;
- a reproducible Calculon/SeqSel calibration experiment.
- typed decoder-only Transformer training and static prefill/decode frontends;
- `ModelIR -> DistributedTaskIR -> PortablePlanIR` staged derivation with explicit TP collectives, recomputation,
KV state, workload, and buffer facts;
- peak-only, hardware-evidence, database, and explicit roofline fallback cost views;
- reproducible Calculon/SeqSel and Vidur comparison gates that remain downstream of derivation.

First-class architecture blueprints, hardware design variables, concrete resource simulation, network/hardware
simulator adapters, bottleneck/sensitivity reports, energy/area/cost models, and Pareto search are planned product
Expand All @@ -80,38 +80,36 @@ pip install -e ".[dev,docs]"
## Build the current Transformer workload blueprint

```python
from blueprinting.compiler.lowering import (
from blueprinting.synthesizer.lowering import (
DistributeTransformerTrainingPass,
PlanTransformerTrainingPass,
)
from blueprinting.compiler.models import (
TransformerExecutionSpec,
TransformerModelSpec,
build_transformer_model_ir,
compilation_session_for,
)
from blueprinting.compiler.passes import PassManager, PassPipeline
from blueprinting.synthesizer.frontend import build_transformer_model_ir, synthesis_session_for
from blueprinting.synthesizer.passes import PassManager, PassPipeline
from blueprinting.mapping import TransformerTrainingMappingSpec
from blueprinting.workload import TransformerModelSpec, TransformerTrainingWorkloadSpec

model = TransformerModelSpec.from_mapping("gpt3-175B", model_config)
execution = TransformerExecutionSpec.from_mapping(execution_config)
source = build_transformer_model_ir(model)
workload = TransformerTrainingWorkloadSpec.from_mapping(execution_config)
mapping = TransformerTrainingMappingSpec.from_mapping(execution_config)
source = build_transformer_model_ir(model, datatype=workload.datatype)

result = PassManager().run(
PassPipeline.of(
DistributeTransformerTrainingPass(),
PlanTransformerTrainingPass(),
),
source,
session=compilation_session_for(model, execution),
session=synthesis_session_for(model, workload, mapping),
)

portable_plan = result.ir
for checkpoint in result.checkpoints:
print(checkpoint.pass_name, checkpoint.ir.digest)
```

The mapping inputs use the model and execution schemas in `data/`. Invalid topology such as
`world_size != tp * pp * dp` is rejected at the typed frontend boundary.
The adapter reads the retained model/execution JSON presets in `data/`, then separates workload facts from the
logical mapping. Invalid topology such as `world_size != tp * pp * dp` is rejected at the typed frontend boundary.

## Reproduce the Calculon calibration

Expand Down Expand Up @@ -152,24 +150,24 @@ Calculon remains an adjacent calibration utility and does not participate in the
## Repository layout

```text
src/blueprinting/compiler/
├── ir/ # five canonical IR contracts
├── models/ # typed semantic frontends
├── lowering/ # staged derivation passes
├── analysis/ # exact workload and derived cost analyses
├── experiments/ # reproducible validation experiments
├── passes/ # transformation contracts and manager
└── session.py # explicit bindings and typed derivation context

src/blueprinting/application/ # framework-neutral analysis service
src/blueprinting/schema/ # dependency-free codec and immutable schema primitives
src/blueprinting/workload/ # target-neutral model and scenario facts
src/blueprinting/mapping/ # logical strategies and explicit deployment mappings
src/blueprinting/system/ # chip, memory, interconnect, and system profiles
src/blueprinting/synthesizer/ # canonical IR, exact-work dialects, and verified derivation
src/blueprinting/analysis/ # evidence protocols, cost resolution, and projections
src/blueprinting/application/ # framework-neutral analysis services and reports
src/blueprinting/validation/ # external baselines and strict regression gates
src/blueprinting/workbench/ # NiceGUI workbench and legacy presentation adapters

tests/compiler/ # current formal-representation and calibration tests
docs/ # bilingual MkDocs design, reference, experiment, and project documentation
data/evidence/ # optional external evidence, excluded from the base package
tests/ # domain, derivation, application, and regression contracts
docs/ # bilingual MkDocs design, experiment, and project documentation
```

The `compiler` package path and names such as `CompilationSession` are current implementation identifiers retained
for compatibility; they do not define the product architecture.
`workload`, `mapping`, and `system` own separate input concerns. `synthesizer` derives canonical plans from workload
and logical-strategy contracts without reading a physical system; `analysis` later evaluates those plans against an
explicit system, deployment mapping, and evidence snapshot. External oracles remain downstream in `validation`.

## Development

Expand Down
14 changes: 14 additions & 0 deletions data/evidence/aiconfigurator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AIConfigurator evidence bundle

This directory is an external performance-data snapshot, not a Python package
and not a Blueprinting system contract. Consumers must load individual files
through an explicit evidence importer and record the selected file digest,
runtime/backend revision, hardware identity, and measurement protocol.

The imported snapshot does not currently include one repository-level source
revision manifest. Treat it as exploratory evidence; do not use it as a frozen
regression oracle until provenance and license metadata are pinned for the
whole bundle. The files retain their original SPDX headers where supplied.

The directory is intentionally excluded from default wheel and source
distribution artifacts because it is large and optional.
Loading