mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-12 12:40:20 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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__/
|
||||||
|
|||||||
@@ -86,7 +86,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
|
||||||
@@ -195,6 +195,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)
|
||||||
@@ -266,20 +267,17 @@ 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)
|
||||||
|
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
|
||||||
@@ -311,6 +309,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,13 +327,16 @@ class Trainer(TrainerIO):
|
|||||||
if stop:
|
if stop:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def __run_tng_batch(self, data_batch):
|
def __run_tng_batch(self, data_batch):
|
||||||
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)
|
||||||
@@ -373,6 +378,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
|
|
||||||
+1
@@ -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
|
||||||
@@ -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)
|
||||||
@@ -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.dev15',
|
||||||
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",
|
||||||
@@ -24,34 +21,7 @@ setup(
|
|||||||
"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(),
|
||||||
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