File size: 2,198 Bytes
a25598f
3998c19
 
 
 
 
 
 
 
 
 
 
a25598f
 
3998c19
a25598f
 
 
3998c19
 
 
 
a25598f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3998c19
a25598f
 
 
 
 
3998c19
 
 
 
 
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
"""Loopback-only PILOT policy service, with a fixed checkpoint coordinate system."""
import argparse
import json
import logging
import os
from pathlib import Path


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--checkpoint", required=True)
    parser.add_argument("--port", type=int, required=True)
    parser.add_argument("--output", type=Path, required=True)
    parser.add_argument("--max-vram-gib", type=float, default=40)
    args = parser.parse_args()
    visible = os.environ.get("CUDA_VISIBLE_DEVICES", "")
    if not visible or "," in visible or visible == "-1":
        raise ValueError("Expose exactly one explicitly allocated GPU per policy process.")
    import torch
    from deployment.model_server.tools.websocket_policy_server import WebsocketPolicyServer
    from starVLA.model.framework.base_framework import baseframework

    torch.set_num_threads(4)
    total = torch.cuda.get_device_properties(0).total_memory
    limit = args.max_vram_gib * 1024**3
    if not 0 < limit < total:
        raise ValueError("The policy memory cap must be below device capacity.")
    torch.cuda.set_per_process_memory_fraction(limit / total)
    policy = baseframework.from_pretrained(args.checkpoint, latent_normalization="legacy")
    policy = policy.to(torch.bfloat16).cuda().eval()
    metadata = {
        "protocol": "wm4a_contract_v2_any_physical_step",
        "checkpoint": args.checkpoint, "latent_normalization": "legacy",
        "state_keys": len(policy.state_dict()), "num_frames": 5,
        "action_steps": policy.action_model.num_inference_timesteps,
        "physical_policy_gpu": visible,
        "native_convention": policy.backbone.native_latent_convention,
        "pid": os.getpid(),
    }
    if metadata["action_steps"] != 20:
        raise ValueError("The release protocol requires 20 action sampling steps.")
    args.output.write_text(json.dumps(metadata, indent=2) + "\n")
    WebsocketPolicyServer(policy, host="127.0.0.1", port=args.port,
                          idle_timeout=-1, metadata=metadata).serve_forever()


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO, force=True)
    main()