viiccwen commented on code in PR #1483:
URL: https://github.com/apache/mahout/pull/1483#discussion_r4003220664


##########
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:
   For IQP, IQP-Z, and phase, an `f32` request is normalized to `f64` by the 
Rust pipeline because these encodings do not support the f32 path. This still 
records those measurements as `iqp/f32`, `iqp-z/f32`, and `phase/f32`, so the 
baseline reports f32 coverage while measuring f64. Could unsupported cells be 
skipped, or could the effective dtype be recorded instead? Otherwise, a future 
real f32 implementation would be compared against an f64 baseline.



##########
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:
   Adding phase to this dispatcher with Rust backend will be fine. However, 
pytorch backend still treats phase like amplitude, and make it error.



-- 
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]

Reply via email to