diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index ddd13b09..00000000 --- a/.coveragerc +++ /dev/null @@ -1,22 +0,0 @@ -[run] -source = - seq2seq - -include = - seq2seq/* - seq2seq/data/* - seq2seq/decoders/* - seq2seq/encoders/* - seq2seq/inference/* - seq2seq/metrics/* - seq2seq/models/* - seq2seq/tasks/* - seq2seq/training/* - -omit = - seq2seq/contrib/* - seq2seq/test/* - seq2seq/scripts/* - -[report] -show_missing=True \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 8e2a599d..00000000 --- a/.gitignore +++ /dev/null @@ -1,156 +0,0 @@ -# Created by https://www.gitignore.io/api/python - -notebooks/WIP - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# dotenv -.env - -# virtualenv -.venv/ -venv/ -ENV/ - -# Spyder project settings -.spyderproject - -# Rope project settings -.ropeproject - -# Sublime -.sublimelinterrc - -# Tensorflow -.tfprof_history.txt - -# Mac OS X -.DS_Store - -# MkDocs -site/ - -### Emacs ### -# -*- mode: gitignore; -*- -*~ -\#*\# -/.emacs.desktop -/.emacs.desktop.lock -*.elc -auto-save-list -tramp -.\#* - -# Org-mode -.org-id-locations -*_archive - -# flymake-mode -*_flymake.* - -# eshell files -/eshell/history -/eshell/lastdir - -# elpa packages -/elpa/ - -# reftex files -*.rel - -# AUCTeX auto folder -/auto/ - -# cask packages -.cask/ -dist/ - -# Flycheck -flycheck_*.el - -# server auth directory -/server/ - -# projectiles files -.projectile - -# directory configuration -.dir-locals.el - -# End of https://www.gitignore.io/api/emacs \ No newline at end of file diff --git a/.style.yapf b/.style.yapf deleted file mode 100644 index f499f526..00000000 --- a/.style.yapf +++ /dev/null @@ -1,4 +0,0 @@ -[style] -based_on_style = google -indent_width = 2 -column_limit = 80 \ No newline at end of file diff --git a/bin/train.py b/bin/train.py index 1b0bf867..8c73d350 100755 --- a/bin/train.py +++ b/bin/train.py @@ -32,7 +32,6 @@ from tensorflow import gfile from seq2seq import models -from seq2seq.contrib.experiment import Experiment as PatchedExperiment from seq2seq.configurable import _maybe_load_yaml, _create_from_dict from seq2seq.configurable import _deep_merge_dict from seq2seq.data import input_pipeline @@ -79,7 +78,7 @@ to. If None, a local temporary directory is created.""") # Training parameters -tf.flags.DEFINE_string("schedule", "continuous_train_and_eval", +tf.flags.DEFINE_string("schedule", None, """Estimator function to call, defaults to continuous_train_and_eval for local run""") tf.flags.DEFINE_integer("train_steps", None, @@ -106,13 +105,13 @@ """In addition to keeping the most recent checkpoint files, keep one checkpoint file for every N hours of training.""") -tf.flags.DEFINE_float("gpu_memory_fraction", 1.0, +tf.flags.DEFINE_float("gpu_memory_fraction", 0.6, """Fraction of GPU memory used by the process on each GPU uniformly on the same machine.""") -tf.flags.DEFINE_boolean("gpu_allow_growth", False, +tf.flags.DEFINE_boolean("gpu_allow_growth", True, """Allow GPU memory allocation to grow dynamically.""") -tf.flags.DEFINE_boolean("log_device_placement", False, +tf.flags.DEFINE_boolean("log_device_placement", True, """Log the op placement to devices""") @@ -126,14 +125,16 @@ def create_experiment(output_dir): output_dir: Output directory for model checkpoints and summaries. """ + session_config = tf.ConfigProto() + session_config.gpu_options.allow_growth = FLAGS.gpu_allow_growth + session_config.gpu_options.per_process_gpu_memory_fraction = FLAGS.gpu_memory_fraction config = run_config.RunConfig( tf_random_seed=FLAGS.tf_random_seed, save_checkpoints_secs=FLAGS.save_checkpoints_secs, save_checkpoints_steps=FLAGS.save_checkpoints_steps, keep_checkpoint_max=FLAGS.keep_checkpoint_max, keep_checkpoint_every_n_hours=FLAGS.keep_checkpoint_every_n_hours, - gpu_memory_fraction=FLAGS.gpu_memory_fraction) - config.tf_config.gpu_options.allow_growth = FLAGS.gpu_allow_growth + session_config=session_config) config.tf_config.log_device_placement = FLAGS.log_device_placement train_options = training_utils.TrainOptions( @@ -203,7 +204,7 @@ def model_fn(features, labels, params, mode): metric = _create_from_dict(dict_, metric_specs) eval_metrics[metric.name] = metric - experiment = PatchedExperiment( + experiment = tf.contrib.learn.Experiment( estimator=estimator, train_input_fn=train_input_fn, eval_input_fn=eval_input_fn, diff --git a/example_configs/nmt_large.yml b/example_configs/nmt_large.yml index 1b85b01e..8fff0c25 100644 --- a/example_configs/nmt_large.yml +++ b/example_configs/nmt_large.yml @@ -26,7 +26,7 @@ model_params: optimizer.name: Adam optimizer.params: epsilon: 0.0000008 - optimizer.learning_rate: 0.0001 + optimizer.learning_rate: 0.001 source.max_seq_len: 50 source.reverse: false target.max_seq_len: 50 diff --git a/example_configs/nmt_medium.yml b/example_configs/nmt_medium.yml index 3b4dfa34..f5c4a95b 100644 --- a/example_configs/nmt_medium.yml +++ b/example_configs/nmt_medium.yml @@ -24,9 +24,7 @@ model_params: dropout_output_keep_prob: 1.0 num_layers: 2 optimizer.name: Adam - optimizer.params: - epsilon: 0.0000008 - optimizer.learning_rate: 0.0001 + optimizer.learning_rate: 0.001 source.max_seq_len: 50 source.reverse: false target.max_seq_len: 50 diff --git a/example_configs/nmt_small.yml b/example_configs/nmt_small.yml index 1ca5318b..77f02546 100644 --- a/example_configs/nmt_small.yml +++ b/example_configs/nmt_small.yml @@ -26,7 +26,7 @@ model_params: optimizer.name: Adam optimizer.params: epsilon: 0.0000008 - optimizer.learning_rate: 0.0001 + optimizer.learning_rate: 0.001 source.max_seq_len: 50 source.reverse: false target.max_seq_len: 50 \ No newline at end of file diff --git a/example_configs/text_metrics_bpe.yml b/example_configs/text_metrics_bpe.yml index 14426065..3104c700 100644 --- a/example_configs/text_metrics_bpe.yml +++ b/example_configs/text_metrics_bpe.yml @@ -7,31 +7,3 @@ metrics: - class: BleuMetricSpec params: <<: *default_params - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_1/f_score - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_1/r_score - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_1/p_score - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_2/f_score - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_2/r_score - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_2/p_score - - class: RougeMetricSpec - params: - <<: *default_params - rouge_type: rouge_l/f_score diff --git a/example_configs/train_seq2seq.yml b/example_configs/train_seq2seq.yml index 0f601075..cda287c0 100644 --- a/example_configs/train_seq2seq.yml +++ b/example_configs/train_seq2seq.yml @@ -1,8 +1,8 @@ -buckets: 10,20,30,40 -hooks: - - class: PrintModelAnalysisHook - - class: MetadataCaptureHook - - class: SyncReplicasOptimizerHook - - class: TrainSampleHook - params: - every_n_steps: 1000 +buckets: 10,20,30,40 +hooks: + - class: PrintModelAnalysisHook + - class: MetadataCaptureHook + - class: SyncReplicasOptimizerHook + - class: TrainSampleHook + params: + every_n_steps: 1000 diff --git a/seq2seq/contrib/seq2seq/helper.py b/seq2seq/contrib/seq2seq/helper.py index 977d0ab9..ff0dcc2f 100644 --- a/seq2seq/contrib/seq2seq/helper.py +++ b/seq2seq/contrib/seq2seq/helper.py @@ -32,8 +32,8 @@ import six -from tensorflow.contrib.distributions.python.ops import bernoulli -from tensorflow.contrib.distributions.python.ops import categorical +from tensorflow.contrib.distributions import Bernoulli +from tensorflow.contrib.distributions import Categorical from tensorflow.python.framework import dtypes from tensorflow.python.framework import ops from tensorflow.python.layers import base as layers_base @@ -264,7 +264,7 @@ def sample(self, time, outputs, state, name=None): select_sample_noise = random_ops.random_uniform( [self.batch_size], seed=self._scheduling_seed) select_sample = (self._sampling_probability > select_sample_noise) - sample_id_sampler = categorical.Categorical(logits=outputs) + sample_id_sampler = Categorical(logits=outputs) return array_ops.where( select_sample, sample_id_sampler.sample(seed=self._seed), @@ -384,8 +384,8 @@ def initialize(self, name=None): def sample(self, time, outputs, state, name=None): with ops.name_scope(name, "ScheduledOutputTrainingHelperSample", [time, outputs, state]): - sampler = bernoulli.Bernoulli(probs=self._sampling_probability) - return math_ops.cast( + sampler = Bernoulli(probs=self._sampling_probability) + return math_ops.cast( sampler.sample(sample_shape=self.batch_size, seed=self._seed), dtypes.bool) diff --git a/seq2seq/test/pipeline_test.py b/seq2seq/test/pipeline_test.py index 8456997b..87fc6c2a 100644 --- a/seq2seq/test/pipeline_test.py +++ b/seq2seq/test/pipeline_test.py @@ -39,10 +39,12 @@ def _clear_flags(): - """Resets Tensorflow's FLAG values""" - #pylint: disable=W0212 - tf.app.flags.FLAGS = tf.app.flags._FlagValues() - tf.app.flags._global_parser = argparse.ArgumentParser() + """Resets Tensorflow's FLAG values""" + #pylint: disable=W0212 + for flag_key in dir(tf.app.flags.FLAGS): + delattr(tf.app.flags.FLAGS, flag_key) + #tf.app.flags.FLAGS = tf.app.flags._FlagValues() + tf.app.flags._global_parser = argparse.ArgumentParser() class PipelineTest(tf.test.TestCase): diff --git a/seq2seq/training/utils.py b/seq2seq/training/utils.py index 9451d57c..e73ebac0 100644 --- a/seq2seq/training/utils.py +++ b/seq2seq/training/utils.py @@ -115,7 +115,7 @@ def cell_from_spec(cell_classname, cell_params): cell_class = locate(cell_classname) or getattr(rnn_cell, cell_classname) # Make sure additional arguments are valid - cell_args = set(inspect.getargspec(cell_class.__init__).args[1:]) + cell_args = set(inspect.signature(cell_class.__init__).parameters) for key in cell_params.keys(): if key not in cell_args: raise ValueError(