Repository: pytorch
Issue: [Feature Request] add graph to hparams for tensorboard
Labels: module: tensorboard,oncall: visualization

## 🚀 Feature

I request that adding graphs of add_scalar to the hparams in tensorbaord.
The image below shows what I want

![image](https://user-images.githubusercontent.com/8328986/130320507-36b8ad25-0428-4d5c-9b9d-5b31705cc87e.png)
![image](https://user-images.githubusercontent.com/8328986/130320511-ece42194-b9ea-41a8-8abc-490b1ae8a17b.png)

These images were cited from [here](https://discuss.pytorch.org/t/how-to-add-graphs-to-hparams-in-tensorboard/109349).

## Motivation
I think add_hparams is mostly used together with add_scalar in deep learning. However, It can't embed the graph of add_scalar in hparams. 
This has been pointed out on the [pytorch forum](https://discuss.pytorch.org/t/how-to-add-graphs-to-hparams-in-tensorboard/109349).
Also, add_hparams generates an event file independently of add_scalar. Since this goes against the intuition of one event file per one experiment, I cannot use the tensorboard log intuitively.
This discussion may be related to this issue https://github.com/pytorch/pytorch/issues/32651

<!-- Please outline the motivation for the proposal. Is your feature request related to a problem? e.g., I'm always frustrated when [...]. If this is related to another GitHub issue, please link here too -->


## Pitch
[Current implementation](https://github.com/pytorch/pytorch/blob/master/torch/utils/tensorboard/writer.py#L300
)
```
        torch._C._log_api_usage_once("tensorboard.logging.add_hparams")
        if type(hparam_dict) is not dict or type(metric_dict) is not dict:
            raise TypeError('hparam_dict and metric_dict should be dictionary.')
        exp, ssi, sei = hparams(hparam_dict, metric_dict, hparam_domain_discrete)

        if not run_name:
            run_name = str(time.time())
        logdir = os.path.join(self._get_file_writer().get_logdir(), run_name)
        with SummaryWriter(log_dir=logdir) as w_hp:
            w_hp.file_writer.add_summary(exp)
            w_hp.file_writer.add_summary(ssi)
            w_hp.file_writer.add_summary(sei)
            for k, v in metric_dict.items():
                w_hp.add_scalar(k, v)
```

Proposed implementation
```
        torch._C._log_api_usage_once("tensorboard.logging.add_hparams")
        if type(hparam_dict) is not dict or type(metric_dict) is not dict:
	        raise TypeError('hparam_dict and metric_dict should be dictionary.')
        exp, ssi, sei = hparams(hparam_dict, metric_dict, hparam_domain_discrete)
        
        self.file_writer.add_summary(exp)
        self.file_writer.add_summary(ssi)
        self.file_writer.add_summary(sei)
        for k, v in metric_dict.items():
	        if v is not None:
		        self.add_scalar(k, v)
```

You can use Summary Writer for using this as follows.
```
from torch.utils.tensorboard import SummaryWriter


for i in range(5):
    save_metrics = {'train/acc': None, 'train/loss': None}
    writer = SummaryWriter(f'runs/{i}')
    for step in range(50):
        writer.add_scalar('train/acc', 10*i+step, step)
        writer.add_scalar('train/loss', 10*i - step, step)
    writer.add_hparams({'lr': 0.1*i, 'bsize': i}, save_metrics)
writer.close()
```

Results image

HPARAMS
![image](https://user-images.githubusercontent.com/8328986/130320266-5d1c7744-edb4-4ebf-8de4-ac93bef8d2e9.png)

SCALARS
![image](https://user-images.githubusercontent.com/8328986/130320272-481f06a0-76a7-43a6-bd29-26ef3a68e536.png)

Pros:
- It can embed the SCALARS graphs into HPARAMS.
- No additional event files will be generated. In other words, one event file will be generated for one hyperparameters set.
- `writer.add_hparams` has a simple interface that uses the keys of 'add_scalar'

I used
- tensorboard = "2.6.0"
- torch = "1.9.0"

I would be happy to discuss how to make pytorch more user friendly!