Skip to content

Commit

Permalink
Fix/evaluate no grad (#201)
Browse files Browse the repository at this point in the history
* Evaluate functions run with torch.no_grad() by defeault

* Import user-defined evaluation file

* Disable grads during evaluation with user choosing
  • Loading branch information
belerico authored Feb 5, 2024
1 parent 3b46670 commit 062b21b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sheeprl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Dict

import hydra
import torch
from lightning import Fabric
from lightning.fabric.strategies import STRATEGY_REGISTRY, DDPStrategy, SingleDeviceStrategy, Strategy
from omegaconf import DictConfig, OmegaConf, open_dict
Expand Down Expand Up @@ -209,6 +210,8 @@ def eval_algorithm(cfg: DictConfig):
)
task = importlib.import_module(f"{module}.{evaluation_file}")
command = task.__dict__[entrypoint]
if getattr(cfg, "disable_grads", True):
command = torch.no_grad(command)
fabric.launch(command, cfg, state)


Expand Down
1 change: 1 addition & 0 deletions sheeprl/configs/eval_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ fabric:
env:
capture_video: True

disable_grads: True
checkpoint_path: ???

0 comments on commit 062b21b

Please sign in to comment.