|
103 | 103 | OFFICIAL_DATASETS_DISTRIBUTION_VERSION: Final = "4.8.5" |
104 | 104 | RUN_REPORT_KIND: Final = "recurquant_experiment013_calibration_run" |
105 | 105 | RUN_REPORT_SCHEMA: Final = 2 |
| 106 | +CANONICAL_ADAPTER_REVISION: Final = "experiment-013-qwen35-live-adapter-v2" |
| 107 | +CANONICAL_ADAPTER_KERNEL_BACKEND: Final = "transformers_pure_torch_gated_delta_rule" |
| 108 | +CANONICAL_ADAPTER_MODEL_DTYPE: Final = "bfloat16" |
| 109 | +CANONICAL_TORCH_DISTRIBUTION_VERSION: Final = "2.13.0+cu130" |
| 110 | +CANONICAL_TORCH_RUNTIME_VERSION: Final = "2.13.0+cu130" |
| 111 | +CANONICAL_CUDA_RUNTIME_VERSION: Final = "13.0" |
| 112 | +CANONICAL_ADAPTER_QUERY_SHAPE: Final = (1, 1, 16, 128) |
| 113 | +CANONICAL_ADAPTER_STATE_SHAPE: Final = (1, 16, 128, 128) |
| 114 | +CANONICAL_ADAPTER_RECURRENT_LAYER_INDICES: Final = ( |
| 115 | + 0, |
| 116 | + 1, |
| 117 | + 2, |
| 118 | + 4, |
| 119 | + 5, |
| 120 | + 6, |
| 121 | + 8, |
| 122 | + 9, |
| 123 | + 10, |
| 124 | + 12, |
| 125 | + 13, |
| 126 | + 14, |
| 127 | + 16, |
| 128 | + 17, |
| 129 | + 18, |
| 130 | + 20, |
| 131 | + 21, |
| 132 | + 22, |
| 133 | +) |
| 134 | +CANONICAL_ADAPTER_LOADING_DIAGNOSTICS: Final = ( |
| 135 | + "error_msgs", |
| 136 | + "mismatched_keys", |
| 137 | + "missing_keys", |
| 138 | + "unexpected_keys", |
| 139 | +) |
106 | 140 |
|
107 | 141 | QUERY_EMA_DECAY: Final = 2.0 ** (-1.0 / 32.0) |
108 | 142 | QUERY_ENERGY_EPSILON: Final = 1.0e-6 |
@@ -326,6 +360,18 @@ def _nonnegative_int(value: object, *, context: str) -> int: |
326 | 360 | return value |
327 | 361 |
|
328 | 362 |
|
| 363 | +def _canonical_nonnegative_float_hex(value: object, *, context: str) -> float: |
| 364 | + if not isinstance(value, str): |
| 365 | + raise ValueError(f"{context} must be a canonical hexadecimal float") |
| 366 | + try: |
| 367 | + parsed = float.fromhex(value) |
| 368 | + except (OverflowError, ValueError) as exc: |
| 369 | + raise ValueError(f"{context} must be a canonical hexadecimal float") from exc |
| 370 | + if not math.isfinite(parsed) or parsed < 0.0 or value.startswith("-") or parsed.hex() != value: |
| 371 | + raise ValueError(f"{context} must be finite, non-negative, and canonical") |
| 372 | + return parsed |
| 373 | + |
| 374 | + |
329 | 375 | @dataclass(frozen=True, slots=True) |
330 | 376 | class BootstrapIdentityBindings: |
331 | 377 | repository_source_manifest_file_sha256: str |
@@ -5506,6 +5552,40 @@ def _report_bytes( |
5506 | 5552 | return canonical_json_bytes(document) |
5507 | 5553 |
|
5508 | 5554 |
|
| 5555 | +def _frozen_token_sequence_manifest_sha256( |
| 5556 | + records: Sequence[Mapping[str, object]], |
| 5557 | +) -> str: |
| 5558 | + commitments: list[dict[str, object]] = [] |
| 5559 | + for index, record in enumerate(records): |
| 5560 | + if not isinstance(record, Mapping): |
| 5561 | + raise ValueError(f"frozen calibration record {index} is not a mapping") |
| 5562 | + commitments.append( |
| 5563 | + { |
| 5564 | + "identity_record_sha256": _sha256( |
| 5565 | + record.get("identity_record_sha256"), |
| 5566 | + context=f"frozen calibration record {index} identity SHA-256", |
| 5567 | + ), |
| 5568 | + "prompt_token_ids_sha256": _sha256( |
| 5569 | + record.get("prompt_token_ids_sha256"), |
| 5570 | + context=f"frozen calibration record {index} prompt-token SHA-256", |
| 5571 | + ), |
| 5572 | + "sequence_length": _positive_int( |
| 5573 | + record.get("sequence_length"), |
| 5574 | + context=f"frozen calibration record {index} sequence length", |
| 5575 | + ), |
| 5576 | + "sequence_token_ids_sha256": _sha256( |
| 5577 | + record.get("sequence_token_ids_sha256"), |
| 5578 | + context=f"frozen calibration record {index} sequence-token SHA-256", |
| 5579 | + ), |
| 5580 | + "target_token_ids_sha256": _sha256( |
| 5581 | + record.get("target_token_ids_sha256"), |
| 5582 | + context=f"frozen calibration record {index} target-token SHA-256", |
| 5583 | + ), |
| 5584 | + } |
| 5585 | + ) |
| 5586 | + return sha256_bytes(canonical_json_bytes(commitments)) |
| 5587 | + |
| 5588 | + |
5509 | 5589 | def _authenticate_fisher_h1_smoke_prerequisite_unchecked( |
5510 | 5590 | report_bytes: bytes, |
5511 | 5591 | complete_marker_bytes: bytes, |
@@ -5660,19 +5740,147 @@ def _authenticate_fisher_h1_smoke_prerequisite_unchecked( |
5660 | 5740 | runtime = evidence["runtime"] |
5661 | 5741 | if not isinstance(runtime, Mapping): |
5662 | 5742 | raise CalibrationRunError("Fisher H=1 smoke runtime receipt is missing") |
| 5743 | + _exact_fields( |
| 5744 | + runtime, |
| 5745 | + { |
| 5746 | + "adapter", |
| 5747 | + "authenticated_distribution_count", |
| 5748 | + "authenticated_file_count", |
| 5749 | + "cuda_available", |
| 5750 | + "cuda_runtime", |
| 5751 | + "elapsed_seconds_hex", |
| 5752 | + "gpu", |
| 5753 | + "packages", |
| 5754 | + "platform", |
| 5755 | + "python", |
| 5756 | + "runtime_manifest_file_sha256", |
| 5757 | + "torch", |
| 5758 | + }, |
| 5759 | + context="Fisher H=1 smoke runtime receipt", |
| 5760 | + ) |
| 5761 | + expected_packages = dict(authenticated_runtime.distributions) |
5663 | 5762 | if ( |
5664 | | - runtime.get("runtime_manifest_file_sha256") != authenticated_runtime.manifest_file_sha256 |
5665 | | - or runtime.get("authenticated_distribution_count") |
5666 | | - != authenticated_runtime.distribution_count |
5667 | | - or runtime.get("authenticated_file_count") != authenticated_runtime.file_count |
5668 | | - or runtime.get("packages") != dict(authenticated_runtime.distributions) |
5669 | | - or runtime.get("cuda_available") is not True |
5670 | | - or not isinstance(runtime.get("gpu"), Mapping) |
| 5763 | + runtime["runtime_manifest_file_sha256"] != authenticated_runtime.manifest_file_sha256 |
| 5764 | + or runtime["authenticated_distribution_count"] != authenticated_runtime.distribution_count |
| 5765 | + or type(runtime["authenticated_distribution_count"]) is not int |
| 5766 | + or runtime["authenticated_file_count"] != authenticated_runtime.file_count |
| 5767 | + or type(runtime["authenticated_file_count"]) is not int |
| 5768 | + or runtime["packages"] != expected_packages |
| 5769 | + or runtime["python"] != authenticated_runtime.python_version |
| 5770 | + or expected_packages.get("torch") != CANONICAL_TORCH_DISTRIBUTION_VERSION |
| 5771 | + or runtime["torch"] != CANONICAL_TORCH_RUNTIME_VERSION |
| 5772 | + or runtime["cuda_available"] is not True |
| 5773 | + or runtime["cuda_runtime"] != CANONICAL_CUDA_RUNTIME_VERSION |
| 5774 | + or not isinstance(runtime["platform"], str) |
| 5775 | + or not runtime["platform"] |
5671 | 5776 | ): |
5672 | 5777 | raise CalibrationRunError("Fisher H=1 smoke runtime identity drifted") |
| 5778 | + _canonical_nonnegative_float_hex( |
| 5779 | + runtime["elapsed_seconds_hex"], |
| 5780 | + context="Fisher H=1 smoke elapsed seconds", |
| 5781 | + ) |
| 5782 | + |
| 5783 | + gpu = runtime["gpu"] |
| 5784 | + if not isinstance(gpu, Mapping): |
| 5785 | + raise CalibrationRunError("Fisher H=1 smoke GPU receipt is missing") |
| 5786 | + _exact_fields( |
| 5787 | + gpu, |
| 5788 | + { |
| 5789 | + "capability", |
| 5790 | + "device_index", |
| 5791 | + "name", |
| 5792 | + "peak_allocated_bytes", |
| 5793 | + "peak_reserved_bytes", |
| 5794 | + }, |
| 5795 | + context="Fisher H=1 smoke GPU receipt", |
| 5796 | + ) |
| 5797 | + device_index = _nonnegative_int( |
| 5798 | + gpu["device_index"], |
| 5799 | + context="Fisher H=1 smoke GPU device index", |
| 5800 | + ) |
| 5801 | + capability = gpu["capability"] |
| 5802 | + if ( |
| 5803 | + not isinstance(capability, list) |
| 5804 | + or len(capability) != 2 |
| 5805 | + or type(capability[0]) is not int |
| 5806 | + or capability[0] <= 0 |
| 5807 | + or type(capability[1]) is not int |
| 5808 | + or capability[1] < 0 |
| 5809 | + or not isinstance(gpu["name"], str) |
| 5810 | + or not gpu["name"] |
| 5811 | + ): |
| 5812 | + raise CalibrationRunError("Fisher H=1 smoke GPU identity drifted") |
| 5813 | + peak_allocated = _nonnegative_int( |
| 5814 | + gpu["peak_allocated_bytes"], |
| 5815 | + context="Fisher H=1 smoke GPU peak allocated bytes", |
| 5816 | + ) |
| 5817 | + peak_reserved = _nonnegative_int( |
| 5818 | + gpu["peak_reserved_bytes"], |
| 5819 | + context="Fisher H=1 smoke GPU peak reserved bytes", |
| 5820 | + ) |
| 5821 | + if peak_reserved < peak_allocated: |
| 5822 | + raise CalibrationRunError("Fisher H=1 smoke GPU peak counters are inconsistent") |
| 5823 | + |
5673 | 5824 | adapter = runtime.get("adapter") |
5674 | | - if not isinstance(adapter, Mapping) or adapter.get("fisher_step_count") != fisher_count: |
5675 | | - raise CalibrationRunError("Fisher H=1 smoke adapter step receipt drifted") |
| 5825 | + if not isinstance(adapter, Mapping): |
| 5826 | + raise CalibrationRunError("Fisher H=1 smoke adapter receipt is missing") |
| 5827 | + _exact_fields( |
| 5828 | + adapter, |
| 5829 | + { |
| 5830 | + "adapter_revision", |
| 5831 | + "capture_input_sha256", |
| 5832 | + "device", |
| 5833 | + "fisher_step_count", |
| 5834 | + "kernel_backend", |
| 5835 | + "materialization_attempted", |
| 5836 | + "materialized_sequence_count", |
| 5837 | + "model_dtype", |
| 5838 | + "model_id", |
| 5839 | + "model_loaded", |
| 5840 | + "model_loading_diagnostic_counts", |
| 5841 | + "model_revision", |
| 5842 | + "query_shape", |
| 5843 | + "recurrent_layer_indices", |
| 5844 | + "state_shape", |
| 5845 | + "token_sequence_manifest_sha256", |
| 5846 | + "transformers_version", |
| 5847 | + }, |
| 5848 | + context="Fisher H=1 smoke adapter receipt", |
| 5849 | + ) |
| 5850 | + diagnostics = adapter["model_loading_diagnostic_counts"] |
| 5851 | + if not isinstance(diagnostics, Mapping): |
| 5852 | + raise CalibrationRunError("Fisher H=1 smoke model diagnostics are missing") |
| 5853 | + _exact_fields( |
| 5854 | + diagnostics, |
| 5855 | + set(CANONICAL_ADAPTER_LOADING_DIAGNOSTICS), |
| 5856 | + context="Fisher H=1 smoke model diagnostics", |
| 5857 | + ) |
| 5858 | + if any(type(diagnostics[name]) is not int or diagnostics[name] != 0 for name in diagnostics): |
| 5859 | + raise CalibrationRunError("Fisher H=1 smoke model diagnostics are not empty") |
| 5860 | + expected_token_sequence_manifest_sha256 = _frozen_token_sequence_manifest_sha256( |
| 5861 | + identity.records |
| 5862 | + ) |
| 5863 | + if ( |
| 5864 | + adapter["adapter_revision"] != CANONICAL_ADAPTER_REVISION |
| 5865 | + or adapter["kernel_backend"] != CANONICAL_ADAPTER_KERNEL_BACKEND |
| 5866 | + or adapter["model_dtype"] != CANONICAL_ADAPTER_MODEL_DTYPE |
| 5867 | + or adapter["model_id"] != model_manifest.model_id |
| 5868 | + or adapter["model_revision"] != model_manifest.revision |
| 5869 | + or adapter["transformers_version"] != model_manifest.transformers_version |
| 5870 | + or adapter["device"] != f"cuda:{device_index}" |
| 5871 | + or adapter["fisher_step_count"] != fisher_count |
| 5872 | + or type(adapter["fisher_step_count"]) is not int |
| 5873 | + or adapter["materialization_attempted"] is not True |
| 5874 | + or adapter["materialized_sequence_count"] != len(identity.records) |
| 5875 | + or type(adapter["materialized_sequence_count"]) is not int |
| 5876 | + or adapter["model_loaded"] is not True |
| 5877 | + or adapter["query_shape"] != list(CANONICAL_ADAPTER_QUERY_SHAPE) |
| 5878 | + or adapter["recurrent_layer_indices"] != list(CANONICAL_ADAPTER_RECURRENT_LAYER_INDICES) |
| 5879 | + or adapter["state_shape"] != list(CANONICAL_ADAPTER_STATE_SHAPE) |
| 5880 | + or adapter["capture_input_sha256"] != identity.identity_input_manifest_sha256 |
| 5881 | + or adapter["token_sequence_manifest_sha256"] != expected_token_sequence_manifest_sha256 |
| 5882 | + ): |
| 5883 | + raise CalibrationRunError("Fisher H=1 smoke adapter identity drifted") |
5676 | 5884 | return sha256_bytes(report_bytes) |
5677 | 5885 |
|
5678 | 5886 |
|
|
0 commit comments