这是indexloc提供的服务,不要输入任何密码
Skip to content

Add Weights and Biases Logger #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2021
Merged

Add Weights and Biases Logger #427

merged 7 commits into from
Aug 30, 2021

Conversation

drozzy
Copy link
Contributor

@drozzy drozzy commented Aug 27, 2021

This fixes #426.

Summary of changes

  1. I renamed BasicLogger to TensorboardLogger and updated references everywhere.
  2. I did NOT change the logging api, since I didn't want to mess stuff up. I am not sure what the right signature for write should be. I just wanted to make it work and not break stuff.
  3. I fixed the imports/exports. Double check the utils/__init__.py please.
  4. I added wandb as a dependency in setup. Perhaps it can only be added as a test-time dependency?
  5. I ran all the pep/type/unit tests. All passed except one failed test (I'm not sure if it was failing before, but I can't see how I would have broken it):
test/modelbased/test_psrl.py::test_psrl reward threshold: 3400
FAILED
FAILED test/modelbased/test_psrl.py::test_psrl - KeyError: 'rew'

  1. I get these errors for docstrings and I've no idea how to fix them:
tianshou/utils/logger/wandb.py:8 in public class `WandBLogger`:
        D208: Docstring is over-indented
tianshou/utils/logger/wandb.py:8 in public class `WandBLogger`:
        D209: Multi-line docstring closing quotes should be on a separate line
  1. All other doc tests pass.

P.S.: As a side note, the unit tests take a really long time to run.

@Trinkle23897
Copy link
Collaborator

I renamed BasicLogger to TensorboardLogger and updated references everywhere.

better to keep BasicLogger for compatibility, I'll fix that

@drozzy
Copy link
Contributor Author

drozzy commented Aug 29, 2021

I renamed BasicLogger to TensorboardLogger and updated references everywhere.

better to keep BasicLogger for compatibility, I'll fix that

I find BaseLogger BasicLogger naming confusing a bit. But maybe we can do it in another release or something.

@Trinkle23897
Copy link
Collaborator

Trinkle23897 commented Aug 29, 2021

I know, I mean

class BasicLogger(TensorboardLogger):
  def __init__(self, *args, **kwargs):
    warnings.warn("better to use TensorboardLogger")
    super().__init__(*args, **kwargs)

@drozzy
Copy link
Contributor Author

drozzy commented Aug 29, 2021

Oooh i see, good idea!

Also, for this I usually see people put something like "Deprecated: use TensorboardLogger instead"

@Trinkle23897
Copy link
Collaborator

In [1]: from tianshou.utils import BasicLogger

In [2]: a=BasicLogger(None)
/home/trinkle/github/tianshou-new/tianshou/utils/logger/tensorboard.py:135: UserWarning: Deprecated soon: BasicLogger has renamed to TensorboardLogger in #427.
  warnings.warn(

@Trinkle23897
Copy link
Collaborator

2. I did NOT change the logging api, since I didn't want to mess stuff up. I am not sure what the right signature for write should be. I just wanted to make it work and not break stuff.

I'm refactoring this part now.

2. Use ``BasicLogger`` which contains a tensorboard;
3. To adjust the save frequency, specify ``save_interval`` when initializing BasicLogger.
2. Use ``TensorboardLogger``;
3. To adjust the save frequency, specify ``save_interval`` when initializing TensorboardLogger.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to resume an experiment with wandb? like #350

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but I've never dealt with it before. I suggest waiting for people who have that specific need to raise an issue.
Because I think to resume it you need to start it differently - and it may be extra complexity not everyone needs.

@@ -22,7 +22,7 @@ class PPOPolicy(A2CPolicy):
:param float dual_clip: a parameter c mentioned in arXiv:1912.09729 Equ. 5,
where c > 1 is a constant indicating the lower bound.
Default to 5.0 (set None if you do not want to use it).
:param bool value_clip: a parameter mentioned in arXiv:1811.02553 Sec. 4.1.
:param bool value_clip: a parameter mentioned in arXiv:1811.02553v3 Sec. 4.1.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2021

Codecov Report

Merging #427 (268ce9d) into master (e4f4f0e) will decrease coverage by 0.13%.
The diff coverage is 91.34%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #427      +/-   ##
==========================================
- Coverage   94.82%   94.68%   -0.14%     
==========================================
  Files          58       60       +2     
  Lines        3807     3820      +13     
==========================================
+ Hits         3610     3617       +7     
- Misses        197      203       +6     
Flag Coverage Δ
unittests 94.68% <91.34%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tianshou/policy/modelfree/ppo.py 93.93% <ø> (ø)
tianshou/utils/logger/wandb.py 58.33% <58.33%> (ø)
tianshou/utils/logger/tensorboard.py 95.12% <95.12%> (ø)
tianshou/utils/logger/base.py 95.83% <95.83%> (ø)
tianshou/utils/__init__.py 100.00% <100.00%> (ø)
tianshou/policy/modelfree/trpo.py 88.52% <0.00%> (-4.92%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4f4f0e...268ce9d. Read the comment docs.

@Trinkle23897
Copy link
Collaborator

@drozzy
Copy link
Contributor Author

drozzy commented Aug 30, 2021

Those runs are not visible to me.
Regarding tests - it's up to you. I'm not really sure how you could test it.

@Trinkle23897
Copy link
Collaborator

Okay so plz review my change

@drozzy
Copy link
Contributor Author

drozzy commented Aug 30, 2021

Looks good to me, I can start using to make sure everything works.

@Trinkle23897 Trinkle23897 linked an issue Aug 30, 2021 that may be closed by this pull request
@Trinkle23897 Trinkle23897 merged commit 8a5e219 into thu-ml:master Aug 30, 2021
Trinkle23897 added a commit that referenced this pull request Sep 8, 2021
- fix a bug in #427: logger.write should pass a dict
- change SubprocVectorEnv to ShmemVectorEnv in atari
- increase logger interval for eps
BFAnas pushed a commit to BFAnas/tianshou that referenced this pull request May 5, 2024
- rename BasicLogger to TensorboardLogger
- refactor logger code
- add WandbLogger

Co-authored-by: Jiayi Weng <trinkle23897@gmail.com>
BFAnas pushed a commit to BFAnas/tianshou that referenced this pull request May 5, 2024
- fix a bug in thu-ml#427: logger.write should pass a dict
- change SubprocVectorEnv to ShmemVectorEnv in atari
- increase logger interval for eps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trainer relies on Logger for some values wandb logger
3 participants