gnn_wm2 / Ctrl-World-Graph /scripts /train_nodeonly.py
EndeavourDD's picture
Upload folder using huggingface_hub (part 17)
f15a766 verified
Raw
History Blame Contribute Delete
1.8 kB
"""Train the NODE-ONLY ablation (isolated wrapper around train_wm_graph.py).
Reuses the ENTIRE original training pipeline (arg parsing, dataset, loop,
checkpointing, sidecar) unchanged, and only swaps the model class to
CtrlWorldGraphNodeOnly via a monkeypatch — so the original code is untouched and
the training recipe is identical to the full edge_transformer run.
Launch exactly like the original, e.g.:
CUDA_VISIBLE_DEVICES=0 python -u scripts/train_nodeonly.py \
--tag ablation_node_only_edge_transformer \
--output-dir model_ckpt/ablation_node_only_edge_transformer \
--tensorboard-log-dir model_ckpt/ablation_node_only_edge_transformer/tensorboard \
--history-corruption --graph-backbone edge_transformer --graph-resampler query \
--max-train-steps 50000 --checkpointing-steps 25000
"""
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
import scripts.train_wm_graph as T # noqa: E402
from graphwm.models.ctrl_world_graph_node_only import CtrlWorldGraphNodeOnly # noqa: E402
from accelerate import Accelerator as _BaseAccelerator # noqa: E402
from accelerate.utils import DistributedDataParallelKwargs # noqa: E402
# ISOLATION: make train_wm_graph.main() instantiate the node-only model.
T.CtrlWorldGraph = CtrlWorldGraphNodeOnly
def _Accelerator(*args, **kwargs):
# node-only strips edges -> edge_proj/edge_bias get no gradient; multi-GPU DDP
# needs find_unused_parameters=True to not error on those unused parameters.
kwargs.setdefault("kwargs_handlers", [DistributedDataParallelKwargs(find_unused_parameters=True)])
return _BaseAccelerator(*args, **kwargs)
T.Accelerator = _Accelerator
if __name__ == "__main__":
T.main(T.parse_args())