Download experiments/tdmpc2/src/train.py from cccat6/FlowMo-WM: direct link, hf CLI and curl.
- Browser
- Download file 525 Bytes
-
https://huggingface.co/cccat6/FlowMo-WM/resolve/main/experiments/tdmpc2/src/train.py
- Command line
-
hf download hf://cccat6/FlowMo-WM/experiments/tdmpc2/src/train.py
-
curl -L -o train.py https://huggingface.co/cccat6/FlowMo-WM/resolve/main/experiments/tdmpc2/src/train.py
525 Bytes
| """TD-MPC2 baseline training entry point.""" | |
| import torch.nn.functional as F | |
| def train(config): | |
| model = config["model"] | |
| optimizer = config["optimizer"] | |
| images, actions, future_actions, targets = config["batch"] | |
| pred = model.rollout(images, actions, future_actions) | |
| z, _ = model.encode(images, actions) | |
| value = model.value(z).mean() | |
| loss = F.mse_loss(pred, targets) + 0.0 * value | |
| optimizer.zero_grad(set_to_none=True) | |
| loss.backward() | |
| optimizer.step() | |
| return float(loss.detach()) | |