Download main.py from sbinabdullah/lorasa-policy: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/sbinabdullah/lorasa-policy/resolve/main/main.py
- Command line
-
hf download hf://sbinabdullah/lorasa-policy/main.py
-
curl -L -o main.py https://huggingface.co/sbinabdullah/lorasa-policy/resolve/main/main.py
2.86 kB
| #!/usr/bin/env python3 | |
| """ | |
| Main entry point for the LoRASA agent server. | |
| """ | |
| import argparse | |
| import os | |
| import sys | |
| from pathlib import Path | |
| import torch | |
| from agent import LoRASAAgent, RLAgent | |
| from agent_server import start_server | |
| def main(): | |
| """Main entry point.""" | |
| parser = argparse.ArgumentParser(description="Start the LoRASA agent server") | |
| parser.add_argument( | |
| "--host", type=str, default="0.0.0.0", help="Host to bind the server to" | |
| ) | |
| parser.add_argument( | |
| "--port", type=int, default=8000, help="Port to bind the server to" | |
| ) | |
| parser.add_argument( | |
| "--backbone-path", | |
| type=str, | |
| default=None, | |
| help="Path to backbone checkpoint (default: checkpoints/lorasa_shared_backbone.pt)", | |
| ) | |
| parser.add_argument( | |
| "--adapter-dir", | |
| type=str, | |
| default=None, | |
| help="Path to adapter directory (default: checkpoints)", | |
| ) | |
| parser.add_argument( | |
| "--device", | |
| type=str, | |
| default=None, | |
| help="Device to use (cuda/cpu, default: auto-detect)", | |
| ) | |
| args = parser.parse_args() | |
| # Determine device | |
| if args.device is None: | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| else: | |
| device = args.device | |
| # Determine paths (use local checkpoints directory in agent folder) | |
| agent_dir = Path(__file__).parent | |
| if args.backbone_path is None: | |
| backbone_path = agent_dir / "checkpoints" / "lorasa_shared_backbone.pt" | |
| else: | |
| backbone_path = Path(args.backbone_path) | |
| if args.adapter_dir is None: | |
| adapter_dir = agent_dir / "checkpoints" | |
| else: | |
| adapter_dir = Path(args.adapter_dir) | |
| if not backbone_path.exists(): | |
| print(f"Error: Backbone file not found: {backbone_path}") | |
| sys.exit(1) | |
| if not adapter_dir.exists(): | |
| print(f"Error: Adapter directory not found: {adapter_dir}") | |
| sys.exit(1) | |
| # Create the LoRASA Agent | |
| try: | |
| agent = LoRASAAgent( | |
| backbone_path=str(backbone_path), | |
| adapter_dir=str(adapter_dir), | |
| device=device, | |
| ) | |
| print(f"✓ LoRASA Agent initialized") | |
| print(f" - Backbone: {backbone_path}") | |
| print(f" - Adapter dir: {adapter_dir}") | |
| print(f" - Device: {device}") | |
| except Exception as e: | |
| print(f"Error initializing agent: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) | |
| # Start the server | |
| print(f"Starting server on {args.host}:{args.port}...") | |
| try: | |
| start_server(agent, args.host, args.port) | |
| except KeyboardInterrupt: | |
| print("\nServer stopped by user") | |
| except Exception as e: | |
| print(f"Server error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |