mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-12 12:40:20 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a519e0755b | ||
|
|
9bf3fcd45e | ||
|
|
88ff860c90 | ||
|
|
edf03063a1 | ||
|
|
32edc6d7b7 | ||
|
|
cd36b63167 | ||
|
|
519d2e9321 | ||
|
|
8cca02d652 | ||
|
|
69274d304d | ||
|
|
d98e799404 | ||
|
|
931a45b760 | ||
|
|
eb5b3cfee1 | ||
|
|
15ca7a40a6 | ||
|
|
96903c7910 | ||
|
|
eb13bb8313 | ||
|
|
d560fac104 | ||
|
|
2d3977046e | ||
|
|
fa0a223ccb | ||
|
|
60d4b80322 | ||
|
|
e052a3bc92 | ||
|
|
35ca80683e | ||
|
|
b2ef6a6366 | ||
|
|
9d19ab5850 | ||
|
|
92f9b3e062 | ||
|
|
5fa2a6a723 | ||
|
|
8531f33549 | ||
|
|
98b26c5c7e | ||
|
|
c973245ba1 | ||
|
|
ed787fb061 | ||
|
|
04681eeda9 | ||
|
|
6519c29119 | ||
|
|
3b0fd7a6cb | ||
|
|
a8e57602d3 | ||
|
|
8836f4f7a5 | ||
|
|
f246ae7fab | ||
|
|
1c7d477d03 | ||
|
|
90a460ec62 | ||
|
|
edd406f419 | ||
|
|
8a68466710 | ||
|
|
4dbf38093a | ||
|
|
38717abcd4 | ||
|
|
8e49fc6cf7 | ||
|
|
5f0a71c414 | ||
|
|
88fbf6cc4b | ||
|
|
7002de1d4e | ||
|
|
fecd6a00cb | ||
|
|
4693276494 | ||
|
|
f228e5ae66 | ||
|
|
e3425ec6a0 | ||
|
|
5a7ad19403 | ||
|
|
d6bc203f05 | ||
|
|
12352f1949 | ||
|
|
f881bf6750 | ||
|
|
0637d8e7a5 | ||
|
|
2514f62913 | ||
|
|
95aee7ff96 | ||
|
|
ffd6dc678c | ||
|
|
1961a6abb2 | ||
|
|
676d76d839 | ||
|
|
b625b293f4 | ||
|
|
333f0fde9b | ||
|
|
4b0b7e5ea3 | ||
|
|
e89da15f18 | ||
|
|
004f015ee0 | ||
|
|
398b709b76 | ||
|
|
e9bcbc2318 | ||
|
|
ee51d7b7bc | ||
|
|
bb75bdf87b |
@@ -7,6 +7,7 @@ test_tube_data/
|
|||||||
datasets/
|
datasets/
|
||||||
model_weights/
|
model_weights/
|
||||||
app/models/
|
app/models/
|
||||||
|
pip-wheel-metadata/
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|||||||
@@ -5,7 +5,14 @@ from pytorch_lightning.root_module.memory import get_gpu_memory_map
|
|||||||
import traceback
|
import traceback
|
||||||
from pytorch_lightning.root_module.model_saving import TrainerIO
|
from pytorch_lightning.root_module.model_saving import TrainerIO
|
||||||
from torch.optim.lr_scheduler import MultiStepLR
|
from torch.optim.lr_scheduler import MultiStepLR
|
||||||
|
from torch.nn import DataParallel
|
||||||
|
import pdb
|
||||||
|
|
||||||
|
try:
|
||||||
|
from apex import amp
|
||||||
|
APEX_AVAILABLE = True
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
APEX_AVAILABLE = False
|
||||||
|
|
||||||
class Trainer(TrainerIO):
|
class Trainer(TrainerIO):
|
||||||
|
|
||||||
@@ -26,6 +33,9 @@ class Trainer(TrainerIO):
|
|||||||
train_percent_check=1.0, val_percent_check=1.0, test_percent_check=1.0, val_check_interval=0.95,
|
train_percent_check=1.0, val_percent_check=1.0, test_percent_check=1.0, val_check_interval=0.95,
|
||||||
log_save_interval=1, add_log_row_interval=1,
|
log_save_interval=1, add_log_row_interval=1,
|
||||||
lr_scheduler_milestones=None,
|
lr_scheduler_milestones=None,
|
||||||
|
use_amp=False,
|
||||||
|
check_grad_nans=False,
|
||||||
|
amp_level='O2',
|
||||||
nb_sanity_val_steps=5):
|
nb_sanity_val_steps=5):
|
||||||
|
|
||||||
# Transfer params
|
# Transfer params
|
||||||
@@ -51,6 +61,10 @@ class Trainer(TrainerIO):
|
|||||||
self.nb_sanity_val_steps = nb_sanity_val_steps
|
self.nb_sanity_val_steps = nb_sanity_val_steps
|
||||||
self.lr_scheduler_milestones = [] if lr_scheduler_milestones is None else [int(x.strip()) for x in lr_scheduler_milestones.split(',')]
|
self.lr_scheduler_milestones = [] if lr_scheduler_milestones is None else [int(x.strip()) for x in lr_scheduler_milestones.split(',')]
|
||||||
self.lr_schedulers = []
|
self.lr_schedulers = []
|
||||||
|
self.amp_level = amp_level
|
||||||
|
self.check_grad_nans = check_grad_nans
|
||||||
|
self.data_parallel_device_ids = [0]
|
||||||
|
self.data_parallel = False
|
||||||
|
|
||||||
# training state
|
# training state
|
||||||
self.optimizers = None
|
self.optimizers = None
|
||||||
@@ -73,6 +87,11 @@ class Trainer(TrainerIO):
|
|||||||
self.__determine_data_use_amount(train_percent_check, val_percent_check, test_percent_check, overfit_pct)
|
self.__determine_data_use_amount(train_percent_check, val_percent_check, test_percent_check, overfit_pct)
|
||||||
print('gpu available: {}, used: {}'.format(torch.cuda.is_available(), self.on_gpu))
|
print('gpu available: {}, used: {}'.format(torch.cuda.is_available(), self.on_gpu))
|
||||||
|
|
||||||
|
# apex test
|
||||||
|
self.use_amp = use_amp and APEX_AVAILABLE
|
||||||
|
if self.use_amp:
|
||||||
|
print('using 16bit precision')
|
||||||
|
|
||||||
def __determine_data_use_amount(self, train_percent_check, val_percent_check, test_percent_check, overfit_pct):
|
def __determine_data_use_amount(self, train_percent_check, val_percent_check, test_percent_check, overfit_pct):
|
||||||
"""
|
"""
|
||||||
Use less data for debugging purposes
|
Use less data for debugging purposes
|
||||||
@@ -86,7 +105,7 @@ class Trainer(TrainerIO):
|
|||||||
self.test_percent_check = overfit_pct
|
self.test_percent_check = overfit_pct
|
||||||
|
|
||||||
def __is_function_implemented(self, f_name):
|
def __is_function_implemented(self, f_name):
|
||||||
f_op = getattr(self, f_name, None)
|
f_op = getattr(self.model, f_name, None)
|
||||||
return callable(f_op)
|
return callable(f_op)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -110,21 +129,21 @@ class Trainer(TrainerIO):
|
|||||||
self.tqdm_metrics = {}
|
self.tqdm_metrics = {}
|
||||||
|
|
||||||
# determine number of training batches
|
# determine number of training batches
|
||||||
nb_tng_batches = self.model.nb_batches(self.tng_dataloader)
|
self.nb_tng_batches = self.model.nb_batches(self.tng_dataloader)
|
||||||
self.nb_tng_batches = int(nb_tng_batches * self.train_percent_check)
|
self.nb_tng_batches = int(self.nb_tng_batches * self.train_percent_check)
|
||||||
|
|
||||||
# determine number of validation batches
|
# determine number of validation batches
|
||||||
nb_val_batches = self.model.nb_batches(self.val_dataloader)
|
self.nb_val_batches = self.model.nb_batches(self.val_dataloader)
|
||||||
nb_val_batches = int(nb_val_batches * self.val_percent_check)
|
self.nb_val_batches = int(self.nb_val_batches * self.val_percent_check)
|
||||||
nb_val_batches = max(1, nb_val_batches)
|
self.nb_val_batches = max(1, self.nb_val_batches)
|
||||||
self.nb_val_batches = nb_val_batches
|
self.nb_val_batches = self.nb_val_batches
|
||||||
|
|
||||||
# determine number of test batches
|
# determine number of test batches
|
||||||
nb_test_batches = self.model.nb_batches(self.test_dataloader)
|
self.nb_test_batches = self.model.nb_batches(self.test_dataloader)
|
||||||
self.nb_test_batches = int(nb_test_batches * self.test_percent_check)
|
self.nb_test_batches = int(self.nb_test_batches * self.test_percent_check)
|
||||||
|
|
||||||
# determine when to check validation
|
# determine when to check validation
|
||||||
self.val_check_batch = int(nb_tng_batches * self.val_check_interval)
|
self.val_check_batch = int(self.nb_tng_batches * self.val_check_interval)
|
||||||
|
|
||||||
def __add_tqdm_metrics(self, metrics):
|
def __add_tqdm_metrics(self, metrics):
|
||||||
for k, v in metrics.items():
|
for k, v in metrics.items():
|
||||||
@@ -151,19 +170,19 @@ class Trainer(TrainerIO):
|
|||||||
outputs = []
|
outputs = []
|
||||||
|
|
||||||
# run training
|
# run training
|
||||||
for i, data_batch in enumerate(dataloader):
|
for batch_i, data_batch in enumerate(dataloader):
|
||||||
|
|
||||||
if data_batch is None:
|
if data_batch is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# stop short when on fast dev run
|
# stop short when on fast dev run
|
||||||
if max_batches is not None and i >= max_batches:
|
if max_batches is not None and batch_i >= max_batches:
|
||||||
break
|
break
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# RUN VALIDATION STEP
|
# RUN VALIDATION STEP
|
||||||
# -----------------
|
# -----------------
|
||||||
output = model.validation_step(data_batch)
|
output = model.validation_step(data_batch, batch_i)
|
||||||
outputs.append(output)
|
outputs.append(output)
|
||||||
|
|
||||||
# batch done
|
# batch done
|
||||||
@@ -195,6 +214,7 @@ class Trainer(TrainerIO):
|
|||||||
# -----------------------------
|
# -----------------------------
|
||||||
def fit(self, model):
|
def fit(self, model):
|
||||||
self.model = model
|
self.model = model
|
||||||
|
model.trainer = self
|
||||||
|
|
||||||
# transfer data loaders from model
|
# transfer data loaders from model
|
||||||
self.__get_dataloaders(model)
|
self.__get_dataloaders(model)
|
||||||
@@ -206,6 +226,14 @@ class Trainer(TrainerIO):
|
|||||||
# filter out the weights that were done on gpu so we can load on good old cpus
|
# filter out the weights that were done on gpu so we can load on good old cpus
|
||||||
self.optimizers = model.configure_optimizers()
|
self.optimizers = model.configure_optimizers()
|
||||||
|
|
||||||
|
if self.use_amp:
|
||||||
|
# An example
|
||||||
|
self.model, optimizer = amp.initialize(
|
||||||
|
self.model, self.optimizers[0], opt_level=self.amp_level,
|
||||||
|
)
|
||||||
|
self.optimizers[0] = optimizer
|
||||||
|
model.trainer = self
|
||||||
|
|
||||||
# add lr schedulers
|
# add lr schedulers
|
||||||
if self.lr_scheduler_milestones is not None:
|
if self.lr_scheduler_milestones is not None:
|
||||||
for optimizer in self.optimizers:
|
for optimizer in self.optimizers:
|
||||||
@@ -217,7 +245,10 @@ class Trainer(TrainerIO):
|
|||||||
|
|
||||||
# put on gpu if needed
|
# put on gpu if needed
|
||||||
if self.on_gpu:
|
if self.on_gpu:
|
||||||
model = model.cuda()
|
if self.data_parallel:
|
||||||
|
model = DataParallel(model, device_ids=self.data_parallel_device_ids)
|
||||||
|
else:
|
||||||
|
model = model.cuda()
|
||||||
|
|
||||||
# run tiny validation to make sure program won't crash during val
|
# run tiny validation to make sure program won't crash during val
|
||||||
_ = self.validate(model, self.val_dataloader, max_batches=self.nb_sanity_val_steps)
|
_ = self.validate(model, self.val_dataloader, max_batches=self.nb_sanity_val_steps)
|
||||||
@@ -266,28 +297,25 @@ class Trainer(TrainerIO):
|
|||||||
if met_batch_limit:
|
if met_batch_limit:
|
||||||
break
|
break
|
||||||
|
|
||||||
# give model a chance to end epoch early
|
|
||||||
if self.model.should_stop_epoch(data_batch):
|
|
||||||
break
|
|
||||||
|
|
||||||
# ---------------
|
# ---------------
|
||||||
# RUN TRAIN STEP
|
# RUN TRAIN STEP
|
||||||
# ---------------
|
# ---------------
|
||||||
self.__run_tng_batch(data_batch)
|
batch_result = self.__run_tng_batch(data_batch, batch_nb)
|
||||||
|
early_stop_epoch = batch_result == -1
|
||||||
|
|
||||||
# ---------------
|
# ---------------
|
||||||
# RUN VAL STEP
|
# RUN VAL STEP
|
||||||
# ---------------
|
# ---------------
|
||||||
is_val_check_batch = (batch_nb + 1) % self.val_check_batch == 0
|
is_val_check_batch = (batch_nb + 1) % self.val_check_batch == 0
|
||||||
if self.fast_dev_run or is_val_check_batch:
|
if self.fast_dev_run or is_val_check_batch or early_stop_epoch:
|
||||||
self.__run_validation()
|
self.__run_validation()
|
||||||
|
|
||||||
# when batch should be saved
|
# when batch should be saved
|
||||||
if (batch_nb + 1) % self.log_save_interval == 0:
|
if (batch_nb + 1) % self.log_save_interval == 0 or early_stop_epoch:
|
||||||
self.experiment.save()
|
self.experiment.save()
|
||||||
|
|
||||||
# when metrics should be logged
|
# when metrics should be logged
|
||||||
if batch_nb % self.add_log_row_interval == 0:
|
if batch_nb % self.add_log_row_interval == 0 or early_stop_epoch:
|
||||||
# count items in memory
|
# count items in memory
|
||||||
# nb_params, nb_tensors = count_mem_items()
|
# nb_params, nb_tensors = count_mem_items()
|
||||||
|
|
||||||
@@ -311,6 +339,10 @@ class Trainer(TrainerIO):
|
|||||||
if self.__is_function_implemented('on_batch_end'):
|
if self.__is_function_implemented('on_batch_end'):
|
||||||
self.model.on_batch_end()
|
self.model.on_batch_end()
|
||||||
|
|
||||||
|
# end epoch early
|
||||||
|
if early_stop_epoch:
|
||||||
|
break
|
||||||
|
|
||||||
# hook
|
# hook
|
||||||
if self.__is_function_implemented('on_epoch_end'):
|
if self.__is_function_implemented('on_epoch_end'):
|
||||||
self.model.on_epoch_end()
|
self.model.on_epoch_end()
|
||||||
@@ -325,24 +357,37 @@ class Trainer(TrainerIO):
|
|||||||
if stop:
|
if stop:
|
||||||
return
|
return
|
||||||
|
|
||||||
def __run_tng_batch(self, data_batch):
|
|
||||||
|
def __run_tng_batch(self, data_batch, batch_nb):
|
||||||
if data_batch is None:
|
if data_batch is None:
|
||||||
return
|
return 0
|
||||||
|
|
||||||
# hook
|
# hook
|
||||||
if self.__is_function_implemented('on_batch_start'):
|
if self.__is_function_implemented('on_batch_start'):
|
||||||
self.model.on_batch_start()
|
response = self.model.on_batch_start(data_batch)
|
||||||
|
if response == -1:
|
||||||
|
return -1
|
||||||
|
|
||||||
if self.enable_tqdm:
|
if self.enable_tqdm:
|
||||||
self.prog_bar.update(1)
|
self.prog_bar.update(1)
|
||||||
|
|
||||||
# forward pass
|
# forward pass
|
||||||
# return a scalar value and a dic with tqdm metrics
|
# return a scalar value and a dic with tqdm metrics
|
||||||
loss, model_specific_tqdm_metrics_dic = self.model.training_step(data_batch)
|
loss, model_specific_tqdm_metrics_dic = self.model.training_step(data_batch, batch_nb)
|
||||||
self.__add_tqdm_metrics(model_specific_tqdm_metrics_dic)
|
self.__add_tqdm_metrics(model_specific_tqdm_metrics_dic)
|
||||||
|
|
||||||
# backward pass
|
# backward pass
|
||||||
loss.backward()
|
if self.use_amp:
|
||||||
|
for optimizer in self.optimizers:
|
||||||
|
with amp.scale_loss(loss, optimizer) as scaled_loss:
|
||||||
|
scaled_loss.backward()
|
||||||
|
else:
|
||||||
|
loss.backward()
|
||||||
|
|
||||||
|
if self.check_grad_nans:
|
||||||
|
for param in self.model.parameters():
|
||||||
|
print(param.grad.float().sum())
|
||||||
|
|
||||||
self.batch_loss_value += loss.item()
|
self.batch_loss_value += loss.item()
|
||||||
|
|
||||||
# gradient update with accumulated gradients
|
# gradient update with accumulated gradients
|
||||||
@@ -373,6 +418,8 @@ class Trainer(TrainerIO):
|
|||||||
if self.__is_function_implemented('on_batch_end'):
|
if self.__is_function_implemented('on_batch_end'):
|
||||||
self.model.on_batch_end()
|
self.model.on_batch_end()
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
def __run_validation(self):
|
def __run_validation(self):
|
||||||
# decide if can check epochs
|
# decide if can check epochs
|
||||||
can_check_epoch = (self.current_epoch + 1) % self.check_val_every_n_epoch == 0
|
can_check_epoch = (self.current_epoch + 1) % self.check_val_every_n_epoch == 0
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
class ModelHooks(torch.nn.Module):
|
class ModelHooks(torch.nn.Module):
|
||||||
def on_batch_start(self):
|
def on_batch_start(self, data_batch):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_batch_end(self):
|
def on_batch_end(self):
|
||||||
@@ -19,5 +19,3 @@ class ModelHooks(torch.nn.Module):
|
|||||||
def on_post_performance_check(self):
|
def on_post_performance_check(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def should_stop_epoch(self, data_batch):
|
|
||||||
return False
|
|
||||||
+9
@@ -1,6 +1,7 @@
|
|||||||
import torch
|
import torch
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import pdb
|
||||||
|
|
||||||
|
|
||||||
class ModelIO(object):
|
class ModelIO(object):
|
||||||
@@ -88,6 +89,7 @@ class TrainerIO(object):
|
|||||||
self.early_stop_callback.wait = checkpoint['early_stop_callback_wait']
|
self.early_stop_callback.wait = checkpoint['early_stop_callback_wait']
|
||||||
self.early_stop_callback.patience = checkpoint['early_stop_callback_patience']
|
self.early_stop_callback.patience = checkpoint['early_stop_callback_patience']
|
||||||
self.global_step = checkpoint['global_step']
|
self.global_step = checkpoint['global_step']
|
||||||
|
self.current_epoch = checkpoint['epoch']
|
||||||
|
|
||||||
# restore the optimizers
|
# restore the optimizers
|
||||||
optimizer_states = checkpoint['optimizer_states']
|
optimizer_states = checkpoint['optimizer_states']
|
||||||
@@ -98,6 +100,9 @@ class TrainerIO(object):
|
|||||||
# PRIVATE OPS
|
# PRIVATE OPS
|
||||||
# ----------------------------------
|
# ----------------------------------
|
||||||
def hpc_save(self, folderpath, experiment):
|
def hpc_save(self, folderpath, experiment):
|
||||||
|
# make sure the checkpoint folder exists
|
||||||
|
os.makedirs(folderpath, exist_ok=True)
|
||||||
|
|
||||||
# save exp to make sure we get all the metrics
|
# save exp to make sure we get all the metrics
|
||||||
experiment.save()
|
experiment.save()
|
||||||
|
|
||||||
@@ -129,6 +134,10 @@ class TrainerIO(object):
|
|||||||
|
|
||||||
def max_ckpt_in_folder(self, path):
|
def max_ckpt_in_folder(self, path):
|
||||||
files = os.listdir(path)
|
files = os.listdir(path)
|
||||||
|
files = [x for x in files if 'ckpt_' in x]
|
||||||
|
if len(files) == 0:
|
||||||
|
return 0
|
||||||
|
|
||||||
ckpt_vs = []
|
ckpt_vs = []
|
||||||
for name in files:
|
for name in files:
|
||||||
name = name.split('ckpt_')[-1]
|
name = name.split('ckpt_')[-1]
|
||||||
+10
-6
@@ -24,6 +24,7 @@ class RootModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
|
|||||||
self.overfit = hparams.overfit
|
self.overfit = hparams.overfit
|
||||||
self.gradient_clip = hparams.gradient_clip
|
self.gradient_clip = hparams.gradient_clip
|
||||||
self.num = 2
|
self.num = 2
|
||||||
|
self.trainer = None
|
||||||
|
|
||||||
# track if gpu was requested for checkpointing
|
# track if gpu was requested for checkpointing
|
||||||
self.on_gpu = False
|
self.on_gpu = False
|
||||||
@@ -39,8 +40,7 @@ class RootModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
|
|||||||
|
|
||||||
if self.on_gpu:
|
if self.on_gpu:
|
||||||
print('running on gpu...')
|
print('running on gpu...')
|
||||||
self.dtype = torch.cuda.FloatTensor
|
torch.set_default_tensor_type(hparams.default_tensor_type)
|
||||||
torch.set_default_tensor_type('torch.cuda.FloatTensor')
|
|
||||||
|
|
||||||
def forward(self, *args, **kwargs):
|
def forward(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@@ -51,7 +51,7 @@ class RootModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def validation_step(self, data_batch):
|
def validation_step(self, data_batch, batch_nb):
|
||||||
"""
|
"""
|
||||||
return whatever outputs will need to be aggregated in validation_end
|
return whatever outputs will need to be aggregated in validation_end
|
||||||
:param data_batch:
|
:param data_batch:
|
||||||
@@ -67,7 +67,7 @@ class RootModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def training_step(self, data_batch):
|
def training_step(self, data_batch, batch_nb):
|
||||||
"""
|
"""
|
||||||
return loss, dict with metrics for tqdm
|
return loss, dict with metrics for tqdm
|
||||||
:param data_batch:
|
:param data_batch:
|
||||||
@@ -150,19 +150,23 @@ class RootModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_from_metrics(cls, weights_path, tags_csv, on_gpu):
|
def load_from_metrics(cls, weights_path, tags_csv, on_gpu, map_location=None):
|
||||||
"""
|
"""
|
||||||
Primary way of loading model from csv weights path
|
Primary way of loading model from csv weights path
|
||||||
:param weights_path:
|
:param weights_path:
|
||||||
:param tags_csv:
|
:param tags_csv:
|
||||||
:param on_gpu:
|
:param on_gpu:
|
||||||
|
:param map_location: dic for mapping storage {'cuda:1':'cuda:0'}
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
hparams = load_hparams_from_tags_csv(tags_csv)
|
hparams = load_hparams_from_tags_csv(tags_csv)
|
||||||
hparams.__setattr__('on_gpu', on_gpu)
|
hparams.__setattr__('on_gpu', on_gpu)
|
||||||
|
|
||||||
if on_gpu:
|
if on_gpu:
|
||||||
checkpoint = torch.load(weights_path)
|
if map_location is not None:
|
||||||
|
checkpoint = torch.load(weights_path, map_location=map_location)
|
||||||
|
else:
|
||||||
|
checkpoint = torch.load(weights_path)
|
||||||
else:
|
else:
|
||||||
checkpoint = torch.load(weights_path, map_location=lambda storage, loc: storage)
|
checkpoint = torch.load(weights_path, map_location=lambda storage, loc: storage)
|
||||||
|
|
||||||
@@ -9,7 +9,6 @@ from pytorch_lightning.utils.arg_parse import add_default_args
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from pytorch_lightning.utils.pt_callbacks import EarlyStopping, ModelCheckpoint
|
from pytorch_lightning.utils.pt_callbacks import EarlyStopping, ModelCheckpoint
|
||||||
|
|
||||||
SEED = 2334
|
SEED = 2334
|
||||||
torch.manual_seed(SEED)
|
torch.manual_seed(SEED)
|
||||||
np.random.seed(SEED)
|
np.random.seed(SEED)
|
||||||
@@ -49,6 +49,11 @@ def add_default_args(parser, root_dir, rand_seed=None, possible_model_names=None
|
|||||||
parser.add_argument('--gpus', default='0', type=str)
|
parser.add_argument('--gpus', default='0', type=str)
|
||||||
parser.add_argument('--single_run_gpu', dest='single_run_gpu', action='store_true')
|
parser.add_argument('--single_run_gpu', dest='single_run_gpu', action='store_true')
|
||||||
parser.add_argument('--disable_cuda', dest='disable_cuda', action='store_true')
|
parser.add_argument('--disable_cuda', dest='disable_cuda', action='store_true')
|
||||||
|
parser.add_argument('--default_tensor_type', default='torch.cuda.FloatTensor', type=str)
|
||||||
|
parser.add_argument('--use_amp', dest='use_amp', action='store_true')
|
||||||
|
parser.add_argument('--check_grad_nans', dest='check_grad_nans', action='store_true')
|
||||||
|
parser.add_argument('--amp_level', default='O2',type=str)
|
||||||
|
|
||||||
|
|
||||||
# run on hpc
|
# run on hpc
|
||||||
parser.add_argument('--on_cluster', dest='on_cluster', action='store_true')
|
parser.add_argument('--on_cluster', dest='on_cluster', action='store_true')
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from setuptools import setup, find_packages, os
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
# https://packaging.python.org/guides/single-sourcing-package-version/
|
# https://packaging.python.org/guides/single-sourcing-package-version/
|
||||||
version = {}
|
|
||||||
with open(os.path.join("src", "pytorch-lightning", "__init__.py")) as fp:
|
|
||||||
exec(fp.read(), version)
|
|
||||||
|
|
||||||
# http://blog.ionelmc.ro/2014/05/25/python-packaging/
|
# http://blog.ionelmc.ro/2014/05/25/python-packaging/
|
||||||
setup(
|
setup(
|
||||||
name="pytorch-lightning",
|
name="pytorch-lightning",
|
||||||
version=version["__version__"],
|
version='0.1.dev21',
|
||||||
description="The Keras for ML researchers using PyTorch",
|
description="The Keras for ML researchers using PyTorch",
|
||||||
author="William Falcon",
|
author="William Falcon",
|
||||||
author_email="waf2107@columbia.edu",
|
author_email="waf2107@columbia.edu",
|
||||||
@@ -20,39 +17,13 @@ setup(
|
|||||||
keywords=["deep learning", "pytorch", "AI"],
|
keywords=["deep learning", "pytorch", "AI"],
|
||||||
python_requires=">=3.5",
|
python_requires=">=3.5",
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"torch",
|
"torch>=1.0.0",
|
||||||
"tqdm",
|
"tqdm",
|
||||||
"test-tube",
|
"test-tube",
|
||||||
],
|
],
|
||||||
extras_require={
|
packages=find_packages(),
|
||||||
"dev": [
|
|
||||||
"black ; python_version>='3.6'",
|
|
||||||
"coverage",
|
|
||||||
"isort",
|
|
||||||
"pytest",
|
|
||||||
"pytest-cov<2.6.0",
|
|
||||||
"pycodestyle",
|
|
||||||
"sphinx",
|
|
||||||
"nbsphinx",
|
|
||||||
"ipython>=5.0",
|
|
||||||
"jupyter-client",
|
|
||||||
]
|
|
||||||
},
|
|
||||||
packages=find_packages("src"),
|
|
||||||
package_dir={"": "src"},
|
|
||||||
classifiers=[
|
|
||||||
"Development Status :: 4 - Beta",
|
|
||||||
"Intended Audience :: Education",
|
|
||||||
"Intended Audience :: Science/Research",
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Operating System :: OS Independent",
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Programming Language :: Python :: 3.5",
|
|
||||||
"Programming Language :: Python :: 3.6",
|
|
||||||
"Programming Language :: Python :: 3.7",
|
|
||||||
],
|
|
||||||
long_description=open("README.md", encoding="utf-8").read(),
|
long_description=open("README.md", encoding="utf-8").read(),
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
"""
|
|
||||||
=================
|
|
||||||
pytorch-lightning
|
|
||||||
=================
|
|
||||||
|
|
||||||
The Keras for ML researchers using PyTorch. More control. Less boilerplate.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
__version__ = "0.1.dev11"
|
|
||||||
Reference in New Issue
Block a user