ryankert01 commented on code in PR #1483: URL: https://github.com/apache/mahout/pull/1483#discussion_r4005352180
########## qdp/qdp-python/benchmark/baseline.py: ########## @@ -0,0 +1,178 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +"""Capture and compare a performance baseline for every encoding. + +Numbers are machine-specific, so the JSON is meant to live outside the repo +(a CI artifact or a scratch directory), not be committed. + + # Before an engine refactor: + python baseline.py capture --out /tmp/qdp-baseline.json + + # After: + python baseline.py compare /tmp/qdp-baseline.json --tolerance 0.05 + +``compare`` exits non-zero when any encoding's throughput drops by more than +``--tolerance`` (a fraction) or its latency rises by more than the same +fraction. Each cell is measured ``--repeats`` times and the best run is kept, +which removes most of the noise from a shared machine. +""" + +from __future__ import annotations + +import argparse +import json +import platform +import subprocess +import sys +import time +from typing import Any + +from qumat_qdp import QdpBenchmark + +ENCODINGS = ("amplitude", "angle", "basis", "iqp", "iqp-z", "phase") +DTYPES = ("f64", "f32") + + +def _gpu_name(device_id: int) -> str: + try: + out = subprocess.run( + [ + "nvidia-smi", + f"--id={device_id}", + "--query-gpu=name", + "--format=csv,noheader", + ], + capture_output=True, + text=True, + check=True, + ) + return out.stdout.strip() + except Exception: # informational only + return "unknown" + + +def measure(args: argparse.Namespace) -> dict[str, Any]: + cells: dict[str, dict[str, float]] = {} + for encoding in ENCODINGS: + for dtype in DTYPES: Review Comment: Good catch, thanks. Fixed in 1dcf7d9: `Encoding::supports_f32` is now exported as `_qdp.encoding_supports_f32`, and `baseline.py` skips `f32` cells for encodings without a native f32 path (currently iqp, iqp-z, phase). Skipped cells are printed and listed under `"skipped"` in the JSON so the omission is visible, and `compare` ignores them. A test checks the exported flag against the parity grid's f32 list, so a real f32 kernel landing later will flip both together. ########## qdp/qdp-python/qumat_qdp/torch_ref.py: ########## @@ -30,7 +30,14 @@ import torch import torch.nn.functional as F -__all__ = ["amplitude_encode", "angle_encode", "basis_encode", "encode", "iqp_encode"] +__all__ = [ + "amplitude_encode", + "angle_encode", + "basis_encode", + "encode", + "iqp_encode", + "phase_encode", Review Comment: Fixed in 1dcf7d9 rather than deferred: the PyTorch backend now treats `phase` like `angle`/`iqp-z` (one angle per qubit), so it no longer falls into the amplitude branch. `test_pytorch_throughput_every_encoding` runs the PyTorch backend for all six encodings. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
