Compare commits
2
Commits
v0.8.1.dev38
...
trinity
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6087c3addb | ||
|
|
99957ccd93 |
+2
-1
@@ -3,7 +3,8 @@
|
||||
url = git@github.com:PrimeIntellect-ai/verifiers.git
|
||||
[submodule "renderers"]
|
||||
path = deps/renderers
|
||||
url = git@github.com:PrimeIntellect-ai/renderers.git
|
||||
url = ../renderers.git
|
||||
branch = trinity
|
||||
[submodule "research-environments"]
|
||||
path = deps/research-environments
|
||||
url = git@github.com:PrimeIntellect-ai/research-environments.git
|
||||
|
||||
Vendored
+1
-1
Submodule deps/renderers updated: bdb96b0c84...e9619bf8f0
@@ -32,6 +32,9 @@ class OptimizerConfig(BaseConfig):
|
||||
|
||||
|
||||
class LoRAConfig(BaseConfig):
|
||||
init_path: Path | None = None
|
||||
"""Initial adapter for a fresh optimizer run; full checkpoint resume takes precedence."""
|
||||
|
||||
name: str | None = None
|
||||
"""LoRA adapter name. If None, auto-generated from rank and alpha."""
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ class IndexCacheConfig(BaseConfig):
|
||||
|
||||
|
||||
class LoRAConfig(BaseConfig):
|
||||
init_path: Path | None = None
|
||||
"""Initialize adapter weights from a PEFT directory when not resuming a full checkpoint."""
|
||||
|
||||
rank: int = Field(16, ge=1)
|
||||
"""Rank of the low-rank decomposition matrices."""
|
||||
|
||||
|
||||
@@ -380,6 +380,15 @@ class Orchestrator:
|
||||
self.policy.model_name = self.lora_name
|
||||
self.policy.version = sync_version
|
||||
|
||||
elif config.model.lora is not None and config.model.lora.init_path is not None:
|
||||
await self.policy_inference.update_weights(
|
||||
config.model.lora.init_path, lora_name=self.lora_name, step=0
|
||||
)
|
||||
self.policy_inference.update_model_name(self.lora_name)
|
||||
self.policy.model_name = self.lora_name
|
||||
self.policy.version = 0
|
||||
get_logger().info(f"Initialized policy v0 from adapter {config.model.lora.init_path}")
|
||||
|
||||
self.train_source = TrainSource(self.train_envs, seed=42)
|
||||
self.eval_source: EvalSource | None = (
|
||||
EvalSource(
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Strict attention-only PEFT initialization without optimizer restoration."""
|
||||
|
||||
import json
|
||||
|
||||
import torch
|
||||
from safetensors.torch import load_file
|
||||
from torch.distributed.tensor import DTensor, distribute_tensor
|
||||
|
||||
from prime_rl.utils.logger import get_logger
|
||||
|
||||
|
||||
def load_attention_adapter(model, config):
|
||||
adapter = config.lora
|
||||
path = adapter.init_path
|
||||
metadata = json.loads((path / "adapter_config.json").read_text())
|
||||
allowed = {"q_proj", "k_proj", "v_proj", "o_proj"}
|
||||
if set(adapter.target_modules) != allowed or adapter.modules_to_save:
|
||||
raise ValueError("Adapter warm start supports only attention q/k/v/o with no modules_to_save")
|
||||
if (metadata.get("r") != adapter.rank or metadata.get("lora_alpha") != adapter.alpha
|
||||
or metadata.get("lora_dropout", 0.0) != adapter.dropout
|
||||
or set(metadata.get("target_modules", [])) != allowed
|
||||
or metadata.get("modules_to_save") or metadata.get("bias", "none") != "none"
|
||||
or metadata.get("base_model_name_or_path") != config.name):
|
||||
raise ValueError("Warm-start adapter metadata does not match trainer configuration")
|
||||
saved = {k.removeprefix("base_model.model."): v for k, v in
|
||||
load_file(str(path / "adapter_model.safetensors"), device="cpu").items()}
|
||||
targets = {}
|
||||
for name, param in model.named_parameters():
|
||||
if ".lora_A." not in name and ".lora_B." not in name:
|
||||
continue
|
||||
name = name.replace("._orig_mod", "")
|
||||
if not name.endswith(".0"):
|
||||
raise ValueError("Adapter warm start supports one adapter slot only")
|
||||
key = name[:-2] + ".weight"
|
||||
if key in targets:
|
||||
raise ValueError(f"Duplicate adapter destination: {key}")
|
||||
targets[key] = param
|
||||
if set(saved) != set(targets):
|
||||
raise ValueError(f"Adapter key mismatch: missing={set(targets)-set(saved)}, extra={set(saved)-set(targets)}")
|
||||
for key, param in targets.items():
|
||||
if saved[key].shape != param.shape or not torch.isfinite(saved[key]).all():
|
||||
raise ValueError(f"Invalid adapter tensor: {key}")
|
||||
with torch.no_grad():
|
||||
for key, param in targets.items():
|
||||
value = saved[key].to(device=param.device, dtype=param.dtype)
|
||||
if isinstance(param, DTensor):
|
||||
value = distribute_tensor(value, param.device_mesh, param.placements)
|
||||
param.copy_(value)
|
||||
actual = param.to_local() if isinstance(param, DTensor) else param
|
||||
expected = value.to_local() if isinstance(value, DTensor) else value
|
||||
if not torch.equal(actual, expected):
|
||||
raise ValueError(f"Adapter copy verification failed: {key}")
|
||||
get_logger().success(f"Warm-started {len(targets)} adapter tensors from {path}; optimizer state is fresh")
|
||||
@@ -173,7 +173,14 @@ def train(config: TrainerConfig):
|
||||
cpu_offload=config.model.optim_cpu_offload,
|
||||
)
|
||||
scheduler = setup_scheduler(optimizer, config.scheduler, config.max_steps, config.optim.lr)
|
||||
# Run creation resets adapters; initialize only after that reset has finished.
|
||||
if checkpoint_step is None and config.model.lora is not None and config.model.lora.init_path is not None:
|
||||
from prime_rl.trainer.lora_init import load_attention_adapter
|
||||
|
||||
load_attention_adapter(model, config.model)
|
||||
else:
|
||||
if config.model.lora is not None and config.model.lora.init_path is not None:
|
||||
raise ValueError("Adapter warm start requires max_concurrent_runs=1")
|
||||
optimizer = setup_multi_optimizer(config.optim, parallel_dims)
|
||||
scheduler = setup_multi_scheduler(optimizer, config.scheduler, config.max_steps)
|
||||
|
||||
|
||||
@@ -457,15 +457,11 @@ def _is_retryable_lora_error(exception: BaseException) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
# Per-attempt and total bounds for `/load_lora_adapter`. A LoRA load is fast
|
||||
# (small adapter file + KV cache reset, single-digit seconds in practice) but
|
||||
# the global admin AsyncClient uses `timeout=None`, so a stuck server hangs
|
||||
# the orchestrator forever inside `ElasticInferencePool._sync_server_adapter`.
|
||||
# `_PER_ATTEMPT` converts a hang into a TimeoutException so tenacity retries;
|
||||
# `_TOTAL` is the wall-clock budget across all retries — pick whichever
|
||||
# stop condition fires first.
|
||||
LORA_LOAD_READ_TIMEOUT_S = 30.0
|
||||
LORA_LOAD_TOTAL_TIMEOUT_S = 120.0
|
||||
# Loaded multi-DP servers can take minutes to finish an adapter update. Keep
|
||||
# finite timeouts without retrying a healthy update after only a few seconds.
|
||||
# The retry budget is checked between attempts, not as a hard outer deadline.
|
||||
LORA_LOAD_READ_TIMEOUT_S = 300.0
|
||||
LORA_LOAD_TOTAL_TIMEOUT_S = 600.0
|
||||
|
||||
|
||||
async def load_lora_adapter(admin_clients: list[AsyncClient], lora_name: str, lora_path: Path) -> None:
|
||||
|
||||
Reference in New Issue
Block a user