Skip to content

Commit 675ea33

Browse files
Merge pull request #3 from rwilliamspbg-ops/copilot/fix-github-actions-test-job
Fix test_throughput_consistency: replace np.datetime64 timing with time.perf_counter_ns
2 parents 18ccc42 + 3b239b7 commit 675ea33

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

prototype/test_correctness_suite.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""
1313

1414
import sys
15+
import time
1516
import numpy as np
1617
import pytest
1718
from prototype.model_tools import ToyModel
@@ -319,19 +320,28 @@ def test_throughput_consistency(self):
319320
for bs in batch_sizes:
320321
x = np.random.randn(bs, 8).astype(np.float32)
321322

322-
# Measure time for single-node
323-
start = np.datetime64('now')
324-
_ = single_node_forward(model, x[0]) # First element only
325-
end = np.datetime64('now')
323+
# Warm up to avoid first-run JIT/cache effects
324+
for _ in range(3):
325+
_ = single_node_forward(model, x[0])
326326

327-
latency = (end - start).astype(np.float64) * 1e9 # nanoseconds
327+
# Take best-of-N to reduce OS scheduling noise
328+
samples = []
329+
for _ in range(10):
330+
start = time.perf_counter_ns()
331+
_ = single_node_forward(model, x[0]) # First element only
332+
end = time.perf_counter_ns()
333+
samples.append(end - start)
328334

329-
latencies.append(latency)
335+
best_latency = float(min(samples)) # nanoseconds
336+
latencies.append(best_latency)
330337

331338
# Latencies should be within 20% of each other (allowing for variance)
332339
min_latency = min(latencies)
333340
max_latency = max(latencies)
334341

342+
if min_latency < 100:
343+
pytest.skip("Timer resolution too low to measure latency reliably")
344+
335345
assert (max_latency - min_latency) / min_latency < 0.2, \
336346
f"Latency variance too high: {min_latency} vs {max_latency}"
337347

0 commit comments

Comments
 (0)