Repository: wandb/wandb

Issue:
Tensorboard: PyTorch writer.add_scalars() does not work as intented.
I tried the code as follows:
```python
from torch.utils.tensorboard import SummaryWriter
import wandb
wandb.tensorboard.patch(tensorboardX=False, pytorch=True)
wandb.init()
writer = SummaryWriter()
scalars = {
    'scalar_1': 1.0,
    'scalar_2': 2.0,
    'scalar_3': 3.0
}
writer.add_scalars('test', scalars, global_step=1)
writer.close()
wandb.finish()
```

My observations:
1. There is a warning that I face with my implementation which is as follows:
```
wandb: WARNING When using several event log directories, please call wandb.tensorboard.patch(root_logdir="...") before wandb.init
```
I have tried figuring out the `root_dir` parameter, due to the unavailability of a docstring or documentation, I was not able to remove the warning.
2. If we ignore the warning the tensorboard integration in wandb does not really work like the one in colab.
|The file structure of the event files that are logged by the `SummaryWriter` are|But in the wandb folder the event files are not structured the same way|
|---|---|
|![image](https://user-images.githubusercontent.com/36856589/100377748-d9c78c00-3037-11eb-9f97-959f83fca1cd.png)|![image](https://user-images.githubusercontent.com/36856589/100377787-f663c400-3037-11eb-9040-e58ba85a4305.png)|

Here we do not see the folders namely `test_scalar_1`, `test_scalar_2`, `test_scalar_3`.

This leads us to the bug in the tensorboard integration

| **Colab tensorboard** | **Tensorboard in wandb**|
|---|---|
|![image](https://user-images.githubusercontent.com/36856589/100377922-42166d80-3038-11eb-998e-1e2eb599182f.png)|![image](https://user-images.githubusercontent.com/36856589/100378164-9588bb80-3038-11eb-885a-2aaaf4219cd5.png)|

Here we do not notice the anything in the `runs` section of `wandb tensorboard`.

I am suspecting a probable issue with https://github.com/wandb/client/blob/30f77c8a320fe42a519f76eb012e61101afad9ba/wandb/integration/tensorboard/monkeypatch.py#L90


Discussion:
Issue-Label Bot is automatically applying the label `bug` to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback! 

 Links: [app homepage](https://github.com/marketplace/issue-label-bot), [dashboard](https://mlbot.net/data/wandb/client) and [code](https://github.com/hamelsmu/MLapp) for this bot.
You just need to call wandb.tensorboard.patch(root_logdir=x) the root logdir is the directory that tensorboard is using as its logdir.  I'm not sure what the default is, maybe os.getcwd but you can also specify a logdir directly in the SummaryWriter instance.
I tried with this code snippet:
```python
from torch.utils.tensorboard import SummaryWriter
import wandb
wandb.tensorboard.patch(root_logdir='runs')
wandb.init(entity="ariG23498", project="errors")
writer = SummaryWriter()
scalars = {
    'scalar_1': 1.0,
    'scalar_2': 2.0,
    'scalar_3': 3.0
}
writer.add_scalars('test', scalars, global_step=1)
writer.close()
wandb.finish()
```
The file structure the SummaryWriter creates is as follows:
![image](https://user-images.githubusercontent.com/36856589/100759328-7f9f4000-3416-11eb-902d-1c58a3a70b98.png)

Here I did mention the root_logdir but the warning still prevails.

Resolving patch:
diff --git a/wandb/integration/tensorboard/monkeypatch.py b/wandb/integration/tensorboard/monkeypatch.py
--- a/wandb/integration/tensorboard/monkeypatch.py
+++ b/wandb/integration/tensorboard/monkeypatch.py
@@ -3,6 +3,8 @@
 """
 
 import os
+import socket
+import re
 
 import wandb
 
@@ -80,8 +82,13 @@ def new_csfw_func(*args, **kwargs):
             wandb.termwarn(
                 'When using several event log directories, please call wandb.tensorboard.patch(root_logdir="...") before wandb.init'
             )
-
-        if root_logdir is not None and not os.path.abspath(logdir).startswith(
+        # if the logdir containts the hostname, the writer was not given a logdir. In this case, the generated logdir
+        # is genetered and ends with the hostname, update the root_logdir to match.
+        hostname = socket.gethostname()
+        search = re.search(r"-\d+_{}".format(hostname), logdir)
+        if search:
+            root_logdir_arg = logdir[: search.span()[1]]
+        elif root_logdir is not None and not os.path.abspath(logdir).startswith(
             os.path.abspath(root_logdir)
         ):
             wandb.termwarn(
@@ -109,12 +116,19 @@ class TBXEventFileWriter(old_efw_class):
         def __init__(self, logdir, *args, **kwargs):
             logdir_hist.append(logdir)
             root_logdir_arg = root_logdir
-            if len(set(logdir_hist)) > 1:
+            if len(set(logdir_hist)) > 1 and root_logdir is None:
                 wandb.termwarn(
                     'When using several event log directories, please call wandb.tensorboard.patch(root_logdir="...") before wandb.init'
                 )
 
-            if root_logdir is not None and not os.path.abspath(logdir).startswith(
+            # if the logdir containts the hostname, the writer was not given a logdir. In this case, the generated logdir
+            # is genetered and ends with the hostname, update the root_logdir to match.
+            hostname = socket.gethostname()
+            search = re.search(r"-\d+_{}".format(hostname), logdir)
+            if search:
+                root_logdir_arg = logdir[: search.span()[1]]
+
+            elif root_logdir is not None and not os.path.abspath(logdir).startswith(
                 os.path.abspath(root_logdir)
             ):
                 wandb.termwarn(


Test patch: