mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
fix default arg (#1927)
* fix default * formatting errors * update * flake8
This commit is contained in:
@@ -154,6 +154,6 @@ def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
|
||||
def convert(val: str) -> Union[int, float, bool, str]:
|
||||
try:
|
||||
return ast.literal_eval(val)
|
||||
except (ValueError, SyntaxError) as e:
|
||||
log.debug(e)
|
||||
except (ValueError, SyntaxError) as err:
|
||||
log.debug(err)
|
||||
return val
|
||||
|
||||
@@ -135,7 +135,7 @@ class CometLogger(LightningLoggerBase):
|
||||
if experiment_name:
|
||||
try:
|
||||
self.name = experiment_name
|
||||
except TypeError as e:
|
||||
except TypeError:
|
||||
log.exception("Failed to set experiment name for comet.ml logger")
|
||||
self._kwargs = kwargs
|
||||
|
||||
|
||||
@@ -177,9 +177,9 @@ def parallel_apply(modules, inputs, kwargs_tup=None, devices=None): # pragma: n
|
||||
|
||||
with lock:
|
||||
results[i] = output
|
||||
except Exception as e:
|
||||
except Exception as ex:
|
||||
with lock:
|
||||
results[i] = e
|
||||
results[i] = ex
|
||||
|
||||
# TODO: fix hack (maybe not a hack)
|
||||
# make sure each module knows what training state it's in...
|
||||
|
||||
@@ -277,7 +277,7 @@ class TrainerDDPMixin(ABC):
|
||||
should_fake = int(os.environ['FAKE_SLURM_MANAGING_TASKS'])
|
||||
if should_fake:
|
||||
self.is_slurm_managing_tasks = True
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# notify user the that slurm is managing tasks
|
||||
|
||||
@@ -343,7 +343,7 @@ from abc import ABC, abstractmethod
|
||||
import time
|
||||
import random
|
||||
import torch
|
||||
from typing import Union
|
||||
from typing import Union, Callable
|
||||
|
||||
from pytorch_lightning import _logger as log
|
||||
from pytorch_lightning.loggers import LightningLoggerBase
|
||||
@@ -748,26 +748,33 @@ def determine_root_gpu_device(gpus):
|
||||
return root_gpu
|
||||
|
||||
|
||||
def retry_jittered_backoff(f, num_retries=5):
|
||||
# Based on:
|
||||
# https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
||||
cap = 1.0 # max sleep time is 1s
|
||||
base = 0.01 # initial sleep time is 10ms
|
||||
sleep = base # initial sleep time is 10ms
|
||||
def retry_jittered_backoff(func: Callable, num_retries: int = 5, cap_delay: float = 1.0, base_delay: float = 0.01):
|
||||
"""Retry jittered backoff.
|
||||
|
||||
Based on:
|
||||
https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
||||
|
||||
Args:
|
||||
func: tested function
|
||||
num_retries: number of tries
|
||||
cap_delay: max sleep time
|
||||
base_delay: initial sleep time is 10ms
|
||||
"""
|
||||
sleep_delay = base_delay # initial sleep time is 10ms
|
||||
|
||||
for i in range(num_retries):
|
||||
try:
|
||||
return f()
|
||||
except RuntimeError as e:
|
||||
return func()
|
||||
except RuntimeError as err:
|
||||
if i == num_retries - 1:
|
||||
raise e
|
||||
raise err
|
||||
else:
|
||||
continue
|
||||
time.sleep(sleep)
|
||||
sleep = min(cap, random.uniform(base, sleep * 3))
|
||||
time.sleep(sleep_delay)
|
||||
sleep_delay = min(cap_delay, random.uniform(base_delay, sleep_delay * 3))
|
||||
|
||||
|
||||
def pick_single_gpu(exclude_gpus=[]):
|
||||
def pick_single_gpu(exclude_gpus: list):
|
||||
for i in range(torch.cuda.device_count()):
|
||||
if i in exclude_gpus:
|
||||
continue
|
||||
@@ -781,9 +788,9 @@ def pick_single_gpu(exclude_gpus=[]):
|
||||
raise RuntimeError("No GPUs available.")
|
||||
|
||||
|
||||
def pick_multiple_gpus(n):
|
||||
def pick_multiple_gpus(nb):
|
||||
picked = []
|
||||
for _ in range(n):
|
||||
for _ in range(nb):
|
||||
picked.append(pick_single_gpu(exclude_gpus=picked))
|
||||
|
||||
return picked
|
||||
|
||||
@@ -84,7 +84,6 @@ At a rough level, here's what happens inside Trainer :py:mod:`pytorch_lightning.
|
||||
"""
|
||||
|
||||
import os
|
||||
import pickle
|
||||
import re
|
||||
import signal
|
||||
from abc import ABC
|
||||
@@ -211,7 +210,7 @@ class TrainerIOMixin(ABC):
|
||||
job_name = os.environ['SLURM_JOB_NAME']
|
||||
if job_name != 'bash':
|
||||
on_slurm = True
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if on_slurm:
|
||||
|
||||
@@ -823,5 +823,5 @@ def test_trainer_subclassing():
|
||||
assert trainer.fast_dev_run
|
||||
|
||||
# when we pass in an unknown arg, the base class should complain
|
||||
with pytest.raises(TypeError, match=r"__init__\(\) got an unexpected keyword argument 'abcdefg'") as e:
|
||||
with pytest.raises(TypeError, match=r"__init__\(\) got an unexpected keyword argument 'abcdefg'"):
|
||||
TrainerSubclass(abcdefg='unknown_arg')
|
||||
|
||||
Reference in New Issue
Block a user