Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
486 changes: 486 additions & 0 deletions examples/vllm_serve/calibrate_mask_reuse.py

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions examples/vllm_serve/create_checkpoint_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Create a deterministic, no-clobber checkpoint manifest for calibration."""

from __future__ import annotations

import argparse
from pathlib import Path

from modelopt.torch.sparsity.attention_sparsity.calibration.checkpoint_manifest import (
create_checkpoint_manifest,
)


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument("checkpoint", type=Path)
parser.add_argument("--model-id", required=True)
args = parser.parse_args(argv)
try:
manifest = create_checkpoint_manifest(args.checkpoint, model=args.model_id)
except (OSError, ValueError) as error:
parser.error(str(error))
print(f"[ModelOpt] Wrote {manifest.manifest_path}")
print(f"CHECKPOINT_MANIFEST_SHA256={manifest.sha256}")
return 0


if __name__ == "__main__":
raise SystemExit(main())
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,54 @@

from .calibrate import calibrate_sparse_attention
from .calibrator import DynamicThresholdCalibrator
from .checkpoint_manifest import (
CHECKPOINT_MANIFEST_NAME,
CheckpointManifestError,
StableFileSnapshot,
VerifiedCheckpointManifest,
create_checkpoint_manifest,
read_stable_file_snapshot,
stable_file_sha256,
verify_checkpoint_manifest,
)
from .mask_reuse import (
AnchorLayerStats,
MaskReuseCalibrationError,
MaskReuseObservation,
calibrate_mask_reuse_policy,
canonical_prefill_threshold_scale_factor,
load_mask_reuse_observations,
parse_mask_reuse_observations,
)
from .mask_reuse_compact import (
CompactMaskReuseCapture,
CompactMaskReuseCaptureSource,
calibrate_compact_mask_reuse_policy,
load_compact_mask_reuse_captures,
)
from .ruler_dataset import RulerDatasetBuilder

__all__ = [
"CHECKPOINT_MANIFEST_NAME",
"AnchorLayerStats",
"CheckpointManifestError",
"CompactMaskReuseCapture",
"CompactMaskReuseCaptureSource",
"DynamicThresholdCalibrator",
"MaskReuseCalibrationError",
"MaskReuseObservation",
"RulerDatasetBuilder",
"StableFileSnapshot",
"VerifiedCheckpointManifest",
"calibrate_compact_mask_reuse_policy",
"calibrate_mask_reuse_policy",
"calibrate_sparse_attention",
"canonical_prefill_threshold_scale_factor",
"create_checkpoint_manifest",
"load_compact_mask_reuse_captures",
"load_mask_reuse_observations",
"parse_mask_reuse_observations",
"read_stable_file_snapshot",
"stable_file_sha256",
"verify_checkpoint_manifest",
]
Loading
Loading