Browse Source

修复Trainer无法捕获Exception的bug

tags/v0.4.10
yh 5 years ago
parent
commit
0257dc6dde
2 changed files with 2 additions and 3 deletions
  1. +1
    -1
      fastNLP/core/trainer.py
  2. +1
    -2
      test/core/test_callbacks.py

+ 1
- 1
fastNLP/core/trainer.py View File

@@ -532,7 +532,7 @@ class Trainer(object):
self._train()
self.callback_manager.on_train_end()

except Exception as e:
except BaseException as e:
self.callback_manager.on_exception(e)
if on_exception == 'auto':
if not isinstance(e, (CallbackException, KeyboardInterrupt)):


+ 1
- 2
test/core/test_callbacks.py View File

@@ -66,8 +66,7 @@ class TestCallback(unittest.TestCase):
dev_data=data_set,
metrics=AccuracyMetric(pred="predict", target="y"),
callbacks=[EarlyStopCallback(5)])
with self.assertRaises(EarlyStopError):
trainer.train()
trainer.train()
def test_lr_scheduler(self):
data_set, model = prepare_env()


Loading…
Cancel
Save