[content] miles/backends/fsdp_utils/update_weight_utils.py (python)
    def update_lora_adapter(self) -> None:
        """Update LoRA adapter using SGLang's unload_lora_adapter and load_lora_adapter endpoints.

        Since update_weights_from_tensor doesn't support LoRA weights, we need to:
        1. Save current LoRA weights to temporary adapter files
        2. Unload current LoRA adapter from SGLang
        3. Load new LoRA adapter from temporary files
        """
        import tempfile
        import json
        from pathlib import Path
        from peft import LoraConfig
        import safetensors.torch

        logger.info(f"[Rank {dist.get_rank()}] Updating LoRA adapter via HTTP endpoints")

        # Extract LoRA weights from model state dict
        lora_state_dict = {k: v for k, v in self.model.state_dict().items() if "lora_" in k}

        # Create temporary directory for adapter files
        with tempfile.TemporaryDirectory() as temp_dir:
            temp_path = Path(temp_dir)

            # Create adapter_config.json
            lora_config = LoraConfig(
                lora_rank=self.args.lora_rank,
                lora_alpha=self.args.lora_alpha,
                lora_dropout=self.args.lora_dropout,
                target_modules=self.args.lora_target_modules,
            )
            peft_config = lora_config.to_hf_peft_config()
            config_path = temp_path / "adapter_config.json"
            with open(config_path, "w") as f:
                json.dump(peft_config, f, indent=2)

            # Save adapter_model.safetensors
            model_path = temp_path / "adapter_model.safetensors"
            safetensors.torch.save_file(lora_state_dict, model_path)

            # TODO: Get server URLs for each rollout engine
            # For now, assume standard localhost URLs - this needs to be implemented properly
            server_urls = self._get_sglang_server_urls()

            # Unload current LoRA adapter and load new one for each server
            for url in server_urls:
                try:
                    # Unload current adapter
                    unload_url = f"{url}/unload_lora_adapter"
                    logger.info(f"Unloading LoRA adapter from {unload_url}")
                    # TODO: Make HTTP call to unload_lora_adapter

                    # Load new adapter
                    load_url = f"{url}/load_lora_adapter"
                    logger.info(f"Loading LoRA adapter from {load_url}")
                    # TODO: Make HTTP call to load_lora_adapter with adapter files

                except Exception as e:
                    logger.error(f"Failed to update LoRA adapter on {url}: {e}")
                    raise

    def _get_sglang_server_urls(self) -> list[str]:
        """Get the HTTP URLs for all SGLang rollout servers.

        TODO: Implement proper URL discovery from rollout engines.
        For now, this is a placeholder.
        """
        # Placeholder implementation - need to get actual server URLs
        # This should query the rollout engines for their HTTP endpoints
        logger.warning("Server URL discovery not implemented - using placeholder")
        return ["http://localhost:30000"]  # Placeholder