-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* RMSProp from timm * Single actor for both discrete/continuous actions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add A2C algo * Print log_dir * Add docs * Add mlflow support * Update README * FIx comments * Add A2C tests * Added model manager A2C config * Fix comments --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
038facd
commit 0633789
Showing
43 changed files
with
976 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,4 +171,5 @@ pytest_* | |
mlruns | ||
mlartifacts | ||
examples/models | ||
session_* | ||
session_* | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# A2C algorithm | ||
Advantage-Actor-Critic (A2C) is an on-policy algorithm that uses the standard policy gradient algorithm, scaled by the advantages, to update the policy. | ||
|
||
From the interaction with the environment, it collects trajectories of *observations*, *actions*, *rewards*, *values*, *logprobs* and *dones*. These trajectories are stored in a buffer, and used to train the policy and value networks. | ||
|
||
Indeed, the training loop consists in sampling a batch of trajectories from the buffer, and computing the *policy loss*, *value loss* and *entropy loss*, while accumulating the gradients over the trajectories collected during the interaction with the environment. By deafult it will sum the gradients over multiple batches, averaging them across all replicas on the last batch seen. | ||
|
||
From the rewards, *returns* and *advantages* are estimated. The *returns*, together with the values stored in the buffer and the values from the updated critic, are used to compute the *value loss*. | ||
|
||
```python | ||
def value_loss( | ||
values: Tensor, | ||
returns: Tensor, | ||
clip_coef: float, | ||
clip_vloss: bool, | ||
) -> Tensor: | ||
return mse_loss(values, returns) | ||
``` | ||
|
||
Advantages and logprobs are used to compute the *policy loss*, using also the logprobs from the updated model. | ||
|
||
```python | ||
def policy_loss(logprobs: Tensor, advantages: Tensor) -> Tensor: | ||
pg_loss = -logprobs * advantages.detach() | ||
reduction = reduction.lower() | ||
if reduction == "none": | ||
return pg_loss | ||
elif reduction == "mean": | ||
return pg_loss.mean() | ||
elif reduction == "sum": | ||
return pg_loss.sum() | ||
else: | ||
raise ValueError(f"Unrecognized reduction: {reduction}") | ||
``` | ||
|
Empty file.
Oops, something went wrong.