File size: 4,156 Bytes
67c4f10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #!/usr/bin/env python3
"""Comprehensive test script verifying Parvulus standalone runtime and Python bindings (Vector-First & Perturbations)."""
import time
import numpy as np
from parvulus_runtime import ParvulusRuntime
def test_vector_and_perturbations():
print("=" * 75)
print(" TESTING PARVULUS STANDALONE RUNTIME: VECTOR-FIRST & PERTURBATIONS")
print("=" * 75)
# 1. Initialize Runtime
print("\n1. Initializing ParvulusRuntime on CUDA:0...")
t0 = time.perf_counter()
runtime = ParvulusRuntime(device_id=0, num_euler_steps=10)
init_ms = (time.perf_counter() - t0) * 1000
print(f" -> Runtime successfully initialized in {init_ms:.1f} ms.")
agent_img = np.zeros((256, 256, 3), dtype=np.uint8)
wrist_img = np.zeros((256, 256, 3), dtype=np.uint8)
# 2. Test First-Class Vector Conditioning
print("\n2. Testing First-Class Vector Conditioning (task_vector)...")
synthetic_vector = np.random.randn(256).astype(np.float32)
synthetic_vector /= np.linalg.norm(synthetic_vector)
runtime.reset(task_vector=synthetic_vector)
chunk_vec = runtime.predict_chunk(agent_img, wrist_img)
print(f" -> Returned chunk shape: {chunk_vec.shape} (dtype: {chunk_vec.dtype})")
print(f" -> Step 0 actions: {np.round(chunk_vec[0], 4)}")
# 3. Test Canonical Instruction String
canonical_prompt = "pick up the black bowl between the plate and the ramekin and place it on the plate"
print(f"\n3. Testing Canonical Prompt: '{canonical_prompt}'...")
runtime.reset(task_description=canonical_prompt)
chunk_canon = runtime.predict_chunk(agent_img, wrist_img)
print(f" -> Step 0 actions: {np.round(chunk_canon[0], 4)}")
# 4. Test Language Perturbations (Unseen Variations)
perturbations = [
"pick up the black bowl and place it on the plate",
"grasp the black bowl between the plate and the ramekin and place it on the plate",
"take the black bowl and set it onto the plate",
"grab the black bowl and put it on the plate",
]
print("\n4. Testing Arbitrary Language Perturbations (Dynamic Vector Encoding)...")
for idx, perturbed_prompt in enumerate(perturbations, start=1):
t0 = time.perf_counter()
runtime.reset(task_description=perturbed_prompt)
chunk_pert = runtime.predict_chunk(agent_img, wrist_img)
dt_ms = (time.perf_counter() - t0) * 1000
# Cosine similarity with canonical conditioning
cos_sim = np.dot(runtime.current_task_vector, runtime.encode_text(canonical_prompt)) / (
np.linalg.norm(runtime.current_task_vector) * np.linalg.norm(runtime.encode_text(canonical_prompt))
)
print(f" [Perturbation {idx}] \"{perturbed_prompt}\"")
print(f" -> Vector Cosine Similarity to Canonical: {cos_sim:.4f}")
print(f" -> Predicted Action [0]: {np.round(chunk_pert[0], 4)} (Reset+Infer: {dt_ms:.1f} ms)")
# 5. Test Step-by-Step Execution with Active Conditioning Vector
print("\n5. Testing step() Receding Horizon with Active Task Vector across 16 steps...")
runtime.reset(task_vector=synthetic_vector)
actions = [runtime.step(agent_img, wrist_img) for _ in range(16)]
print(f" -> Successfully stepped 16 cycles with zero task specification per step.")
print(f" -> Step 0: {np.round(actions[0], 4)}")
print(f" -> Step 8 (replanned): {np.round(actions[8], 4)}")
# 6. Benchmark High-Frequency Control Loop (Vector Already in GPU VRAM)
print("\n6. Benchmarking 100 Consecutive Chunks (Active Vector in GPU VRAM)...")
N = 100
t0 = time.perf_counter()
for _ in range(N):
_ = runtime.predict_chunk(agent_img, wrist_img)
mean_chunk_ms = (time.perf_counter() - t0) * 1000 / N
action_hz = 8.0 / (mean_chunk_ms / 1000.0)
print(f" -> Mean Chunk Latency: {mean_chunk_ms:.3f} ms / chunk")
print(f" -> Effective Action Bandwidth: {action_hz:.1f} Hz (>1,000 Hz target!)")
print("\n" + "=" * 75)
print(" ALL VECTOR-FIRST & PERTURBATION TESTS COMPLETED SUCCESSFULLY!")
print("=" * 75)
if __name__ == "__main__":
test_vector_and_perturbations()
|