目录文档-技术白皮书(V5.05)53-模型卡 Template v1.0

第10章 部署接口与实现绑定(API/函数原型)


I. 目标与范围(Purpose & Scope)


II. 前置条件与输入(Prerequisites & Inputs)


III. 错误语义与返回信封(Error Model & Return Envelope)

{

"status":"OK|ERROR",

"code":0,

"error":{"type":"E_*","message":"...","details":{}},

"payload":{},

"metrics":{"latency_ms":87,"retries":0},

"anchors":["EFT.WP.Core.Equations v1.1:S20-1"],

"version":"1.0.0",

"checksum":"sha256:..."

}


IV. REST OpenAPI(节选)

openapi: 3.0.3

info: { title: "Model Inference API", version: "1.0.0" }

servers: [{ url: "https://api.example.com/v1" }]

components:

securitySchemes: { bearerAuth: { type: http, scheme: bearer } }

schemas:

InferRequest:

type: object

required: [idempotency_key, inputs]

properties:

idempotency_key: { type: string }

inputs: { type: array, items: { type: object } }

options:

type: object

properties:

coverage: { type: string, enum: ["k","alpha","quantile"] }

return_uq: { type: boolean, default: true }

InferResponse:

type: object

properties:

status: { type: string }

payload: { type: object }

uq: { type: object }

anchors: { type: array, items: { type: string } }

version: { type: string }

checksum: { type: string }

paths:

/models/{id}/infer:

post:

security: [{ bearerAuth: [] }]

summary: "Idempotent inference"

parameters: [{ in: path, name: id, required: true, schema: { type: string } }]

requestBody:

required: true

content: { application/json: { schema: { $ref: "#/components/schemas/InferRequest" } } }

responses:

"200": { description: "OK", content: { application/json: { schema: { $ref: "#/components/schemas/InferResponse" } } } }

"409": { description: "Idempotency conflict" }

/models/{id}/validate:

post:

summary: "Validate gates G1–G8 & report stops"

responses: { "200": { description: "Validation report" } }


V. gRPC(proto 节选)

syntax = "proto3";

package model.v1;

message Ctx { string idempotency_key = 1; string coverage = 2; bool return_uq = 3; }

message InferRequest { Ctx ctx = 1; bytes inputs = 2; } // inputs: Avro/JSON/Parquet

message InferResponse {

string status = 1;

bytes payload = 2; // outputs

bytes uq = 3; // optional UQ bundle

repeated string anchors = 4;

string version = 5;

string checksum = 6;

}

service Inference {

rpc Infer (InferRequest) returns (InferResponse);

rpc Validate (InferRequest) returns (InferResponse);

}


VI. CLI(节选)

# 幂等推理

mdl infer mdl-core \

--idempotency_key run42+p010+win001 \

--inputs @samples.json \

--coverage k --return_uq true \

--out outputs/predictions.json

# 门校验

mdl validate mdl-core --out reports/validate_report.json


VII. 实现绑定(函数原型 I60–I69)

  1. I60-infer(ctx, x) -> y | err
    • in:ctx{idempotency_key,coverage,return_uq},x 与《数据集卡》Ch.4 对齐;
    • out:y(含单位/量纲)与可选 uq;
    • 错误:E_INPUT/E_DIM/E_GATE/E_SYNC/E_UQ/E_DRIFT/E_INTERNAL。
  2. I61-validate_gate(card, gates[]) -> report.json:返回 G1–G8 与 stops_triggered。
  3. I62-export_artifacts(fmt) -> {manifest, checksums}:fmt ∈ {zip,tgz}。
  4. I63-path_align(path,inplace=false) -> path':校验 gamma/measure/delta_form 与步长。
  5. I64-derive_arrival(path,c_ref) -> T_arr:T_arr = ( ∫ ( n_eff / c_ref ) d ell )(或常量外提式)。
  6. I65-derive_phase(path,lambda_ref) -> Phi:Phi = ( 2π / λ_ref ) * ( ∫ n_eff d ell )。
  7. I66-uq_delta(J, Σ) -> {u, u_c, U};I67-cov_merge(blocks[]) -> Σ(PD 校验与抖动)。
  8. I68-rollback_fsm(event) -> state:触发回退/降级;
  9. I69-emit_audit(event) -> OK:写 audit.jsonl。

VIII. 路径接口专规(Path-Specific Rules)


IX. 幂等、重试与审计(Idempotency, Retry & Audit)


X. 质量门映射(Gate Mapping)


XI. 机读制品(Machine-Readable Artifacts)
A. inference_openapi.yaml:REST 合约;
B. inference.proto:gRPC 合约;
C. binding_spec.md:入/出字段、单位/量纲、覆盖模式与误差口径;
D. rollback_fsm.yaml:回退状态机;
E. validate_report.json:G1–G8 与 stops_triggered;
F. report_manifest.yaml:制品清单与签名/校验和。


XII. 反例与修正(Anti-Patterns & Fixes)


XIII. 交叉引用(Cross-References)


XIV. 执行勾选清单(Checklist)


版权与许可:除另有说明外,《能量丝理论》(含文本、图表、插图、符号与公式)的著作权由作者(屠广林)享有。
许可方式(CC BY 4.0):在注明作者与来源的前提下,允许复制、转载、节选、改编与再分发。
署名格式(建议):作者:屠广林|作品:《能量丝理论》|来源:energyfilament.org|许可证:CC BY 4.0
验证召集: 作者独立自费、无雇主无资助;下一阶段将优先在最愿意公开讨论、公开复现、公开挑错的环境中推进落地,不限国家。欢迎各国媒体与同行抓住窗口组织验证,并与我们联系。
版本信息: 首次发布:2025-11-11 | 当前版本:v6.0+5.05