Update HFSummaryWriter snippet for a diff

#1
by Wauplin HF staff - opened
Files changed (1) hide show
  1. src/index.md +14 -6
src/index.md CHANGED
@@ -152,13 +152,21 @@ Plot.plot({
152
 
153
  The Tensorboard traces can also easily be uploaded to the Hub using the [huggingface_hub](https://huggingface.co/docs/huggingface_hub/package_reference/tensorboard) library, if you don't rely on Transformers. All it takes is to use the `HFSummaryWriter` class and its methods to append data:
154
 
155
- ```py
156
- from huggingface_hub import HFSummaryWriter
 
 
 
 
 
 
 
157
 
158
- # Logs are automatically pushed every 5 minutes (default) + when exiting the context manager
159
- with HFSummaryWriter(repo_id="test_hf_logger") as logger:
160
- logger.add_scalar("a", 1)
161
- logger.add_scalar("b", 2)
 
162
  ```
163
 
164
  This logger was added in June 2023 in the [v0.16.2](https://github.com/huggingface/huggingface_hub/releases/tag/v0.16.2) version of the library and is a good alternative for those who don't use Transformers. Its usage is still confidential. Feel free to try it and report if it helps you generate training metrics!
 
152
 
153
  The Tensorboard traces can also easily be uploaded to the Hub using the [huggingface_hub](https://huggingface.co/docs/huggingface_hub/package_reference/tensorboard) library, if you don't rely on Transformers. All it takes is to use the `HFSummaryWriter` class and its methods to append data:
154
 
155
+ ```diff
156
+ # Taken from https://pytorch.org/docs/stable/tensorboard.html
157
+ - from torch.utils.tensorboard import SummaryWriter
158
+ + from huggingface_hub import HFSummaryWriter
159
+
160
+ import numpy as np
161
+
162
+ - writer = SummaryWriter()
163
+ + writer = HFSummaryWriter(repo_id="username/my-trained-model")
164
 
165
+ for n_iter in range(100):
166
+ writer.add_scalar('Loss/train', np.random.random(), n_iter)
167
+ writer.add_scalar('Loss/test', np.random.random(), n_iter)
168
+ writer.add_scalar('Accuracy/train', np.random.random(), n_iter)
169
+ writer.add_scalar('Accuracy/test', np.random.random(), n_iter)
170
  ```
171
 
172
  This logger was added in June 2023 in the [v0.16.2](https://github.com/huggingface/huggingface_hub/releases/tag/v0.16.2) version of the library and is a good alternative for those who don't use Transformers. Its usage is still confidential. Feel free to try it and report if it helps you generate training metrics!