Skip to content

Commit

Permalink
Merge branch 'master' into feat/8987
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca authored Aug 22, 2021
2 parents ccbde67 + 13e64e6 commit 49825c7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 27 deletions.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/code_improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Code improvement
about: Suggest a code improvement, i.e. refactoring, deprecation, etc.
title: ''
labels: enhancement, help wanted, refactors / code health
assignees: ''
---

## Proposed refactoring or deprecation

<!-- A clear and concise description of the code improvement -->

### Motivation

<!-- Please outline the motivation for the proposal. If this is related to another GitHub issue, please link here too -->

### Pitch

<!-- A clear and concise description of what you want to happen. -->

### Additional context

<!-- Add any other context or screenshots here. -->

______________________________________________________________________

#### If you enjoy Lightning, check out our other projects! ⚡

<sub>

- [**Metrics**](https://github.com/PyTorchLightning/metrics): Machine learning metrics for distributed, scalable PyTorch applications.

- [**Flash**](https://github.com/PyTorchLightning/lightning-flash): The fastest way to get a Lightning baseline! A collection of tasks for fast prototyping, baselining, finetuning and solving problems with deep learning

- [**Bolts**](https://github.com/PyTorchLightning/lightning-bolts): Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

- [**Lightning Transformers**](https://github.com/PyTorchLightning/lightning-transformers): Flexible interface for high performance research using SOTA Transformers leveraging Pytorch Lightning, Transformers, and Hydra.

</sub>
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Removed `TrainingTypePlugin.on_save` and `Accelerator.on_save` ([#9023](https://github.com/PyTorchLightning/pytorch-lightning/pull/9023))


- Removed deprecated `connect_precision_plugin` and `connect_training_type_plugin` from `Accelerator` ([#9019](https://github.com/PyTorchLightning/pytorch-lightning/pull/9019))


### Fixed

- Ensure the existence of `DDPPlugin._sync_dir` in `reconciliate_processes` ([#8939](https://github.com/PyTorchLightning/pytorch-lightning/pull/8939))
Expand Down
28 changes: 1 addition & 27 deletions pytorch_lightning/accelerators/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pytorch_lightning.plugins.precision import ApexMixedPrecisionPlugin, NativeMixedPrecisionPlugin, PrecisionPlugin
from pytorch_lightning.plugins.training_type import TrainingTypePlugin
from pytorch_lightning.trainer.states import TrainerFn
from pytorch_lightning.utilities import _NATIVE_AMP_AVAILABLE, rank_zero_warn
from pytorch_lightning.utilities import _NATIVE_AMP_AVAILABLE
from pytorch_lightning.utilities.apply_func import apply_to_collection, move_data_to_device
from pytorch_lightning.utilities.enums import AMPType, GradClipAlgorithmType, LightningEnum
from pytorch_lightning.utilities.types import STEP_OUTPUT
Expand Down Expand Up @@ -426,32 +426,6 @@ def model_sharded_context(self) -> Generator[None, None, None]:
with self.training_type_plugin.model_sharded_context():
yield

# todo: remove in v1.5
def connect_training_type_plugin(self, plugin: TrainingTypePlugin, model: "pl.LightningModule") -> None:
"""
Attaches the training type plugin to the accelerator.
Also transfers ownership of the model to this plugin
.. deprecated::v1.3
Will be removed in v1.5.0.
"""
rank_zero_warn(
"Accelerator method `connect_training_type_plugin` was deprecated in v1.3. It will be removed in v1.5."
)
self.setup_training_type_plugin()

# todo: remove in v1.5
def connect_precision_plugin(self, plugin: PrecisionPlugin) -> None:
"""Attaches the precision plugin to the accelerator
.. deprecated::v1.3
Will be removed in v1.5.0.
"""
rank_zero_warn(
"Accelerator method `connect_precision_plugin` was deprecated in v1.3. It will be removed in v1.5."
)
self.setup_precision_plugin()

def save_checkpoint(self, checkpoint: Dict[str, Any], filepath: str) -> None:
"""Save model/training states as a checkpoint file through state-dump and file-write.
Expand Down
3 changes: 3 additions & 0 deletions pytorch_lightning/callbacks/gpu_stats_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def _get_gpu_ids(device_ids: List[int]) -> List[str]:
return [cuda_visible_devices[device_id].strip() for device_id in device_ids]

def _get_gpu_stats(self, queries: List[str]) -> List[List[float]]:
if not queries:
return []

"""Run nvidia-smi to get the gpu stats"""
gpu_query = ",".join(queries)
format = "csv,nounits,noheader"
Expand Down
31 changes: 31 additions & 0 deletions tests/callbacks/test_gpu_stats_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@ def test_gpu_stats_monitor(tmpdir):
assert any(f in h for h in met_data.dtype.names)


@RunIf(min_gpus=1)
def test_gpu_stats_monitor_no_queries(tmpdir):
"""
Test GPU logger doesn't fail if no "nvidia-smi" queries are to be performed.
"""
model = BoringModel()
gpu_stats = GPUStatsMonitor(
memory_utilization=False,
gpu_utilization=False,
intra_step_time=True,
inter_step_time=True,
)
trainer = Trainer(
default_root_dir=tmpdir,
max_epochs=1,
limit_train_batches=2,
limit_val_batches=0,
log_every_n_steps=1,
gpus=1,
callbacks=[gpu_stats],
)
with mock.patch("pytorch_lightning.loggers.tensorboard.TensorBoardLogger.log_metrics") as log_metrics_mock:
trainer.fit(model)

assert log_metrics_mock.mock_calls[2:] == [
mock.call({"batch_time/intra_step (ms)": mock.ANY}, step=0),
mock.call({"batch_time/inter_step (ms)": mock.ANY}, step=1),
mock.call({"batch_time/intra_step (ms)": mock.ANY}, step=1),
]


@pytest.mark.skipif(torch.cuda.is_available(), reason="test requires CPU machine")
def test_gpu_stats_monitor_cpu_machine(tmpdir):
"""
Expand Down

0 comments on commit 49825c7

Please sign in to comment.