From 9c8a8ddff96aa8ab6ca7268b5127ea212271800e Mon Sep 17 00:00:00 2001 From: ydcjeff <32727188+ydcjeff@users.noreply.github.com> Date: Thu, 3 Jun 2021 01:44:16 +0630 Subject: [PATCH 1/2] fix: whitespaces and \n(s) --- src/store.js | 8 +++++--- src/templates/template-common/utils.py | 2 ++ src/templates/template-text-classification/main.py | 2 +- src/templates/template-text-classification/trainers.py | 1 + src/templates/template-text-classification/utils.py | 2 ++ src/templates/template-vision-classification/main.py | 2 +- src/templates/template-vision-classification/trainers.py | 1 + src/templates/template-vision-classification/utils.py | 2 ++ src/templates/template-vision-dcgan/main.py | 2 +- src/templates/template-vision-dcgan/trainers.py | 1 + src/templates/template-vision-dcgan/utils.py | 2 ++ src/templates/template-vision-segmentation/main.py | 2 +- src/templates/template-vision-segmentation/trainers.py | 1 + src/templates/template-vision-segmentation/utils.py | 2 ++ 14 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/store.js b/src/store.js index 7588dcfa..6ade5c93 100644 --- a/src/store.js +++ b/src/store.js @@ -70,9 +70,11 @@ export function genCode() { continue } store.code[file] = ejs - .render(currentFiles[file], store.config) - .replaceAll(/\s{4}\n/gi, '\n') - .replaceAll(/(\n{3,})/gi, '\n\n') + .render( + currentFiles[file].replace(/([\s\n]+#:::\s)/gi, '#::: '), + store.config + ) + .replace(/\s{4}#$/gim, '') } if (isDev) { store.code[__DEV_CONFIG_FILE__] = JSON.stringify(store.config, null, 2) diff --git a/src/templates/template-common/utils.py b/src/templates/template-common/utils.py index 6bfdc7db..09b37fc1 100644 --- a/src/templates/template-common/utils.py +++ b/src/templates/template-common/utils.py @@ -132,6 +132,8 @@ def setup_logging(config: Any) -> Logger: #::: if (it.save_training || it.save_evaluation || it.patience || it.terminate_on_nan || it.limit_sec) { :::# + + def setup_handlers( trainer: Engine, evaluator: Engine, diff --git a/src/templates/template-text-classification/main.py b/src/templates/template-text-classification/main.py index 799e925e..a290924d 100644 --- a/src/templates/template-text-classification/main.py +++ b/src/templates/template-text-classification/main.py @@ -159,7 +159,7 @@ def _(): if rank == 0: exp_logger.close() #::: } :::# - + # #::: if (it.save_training || it.save_evaluation) { :::# # show last checkpoint names logger.info( diff --git a/src/templates/template-text-classification/trainers.py b/src/templates/template-text-classification/trainers.py index 7cd8cf86..e95557e0 100644 --- a/src/templates/template-text-classification/trainers.py +++ b/src/templates/template-text-classification/trainers.py @@ -52,6 +52,7 @@ def train_function(engine: Union[Engine, DeterministicEngine], batch: Any): engine.state.metrics = metric return metric + # #::: if(it.deterministic) { :::# trainer = DeterministicEngine(train_function) #::: } else { :::# diff --git a/src/templates/template-text-classification/utils.py b/src/templates/template-text-classification/utils.py index eef5d85e..11a0ef3c 100644 --- a/src/templates/template-text-classification/utils.py +++ b/src/templates/template-text-classification/utils.py @@ -132,6 +132,8 @@ def setup_logging(config: Any) -> Logger: #::: if (it.save_training || it.save_evaluation || it.patience || it.terminate_on_nan || it.limit_sec) { :::# + + def setup_handlers( trainer: Engine, evaluator: Engine, diff --git a/src/templates/template-vision-classification/main.py b/src/templates/template-vision-classification/main.py index b2d92870..2610e18c 100644 --- a/src/templates/template-vision-classification/main.py +++ b/src/templates/template-vision-classification/main.py @@ -115,7 +115,7 @@ def _(): if rank == 0: exp_logger.close() #::: } :::# - + # #::: if (it.save_training || it.save_evaluation) { :::# # show last checkpoint names logger.info( diff --git a/src/templates/template-vision-classification/trainers.py b/src/templates/template-vision-classification/trainers.py index b25905dc..54ab28ef 100644 --- a/src/templates/template-vision-classification/trainers.py +++ b/src/templates/template-vision-classification/trainers.py @@ -38,6 +38,7 @@ def train_function(engine: Union[Engine, DeterministicEngine], batch: Any): } return {"train_loss": train_loss} + # #::: if(it.deterministic) { :::# trainer = DeterministicEngine(train_function) #::: } else { :::# diff --git a/src/templates/template-vision-classification/utils.py b/src/templates/template-vision-classification/utils.py index ba10476a..3dd5cc5b 100644 --- a/src/templates/template-vision-classification/utils.py +++ b/src/templates/template-vision-classification/utils.py @@ -132,6 +132,8 @@ def setup_logging(config: Any) -> Logger: #::: if (it.save_training || it.save_evaluation || it.patience || it.terminate_on_nan || it.limit_sec) { :::# + + def setup_handlers( trainer: Engine, evaluator: Engine, diff --git a/src/templates/template-vision-dcgan/main.py b/src/templates/template-vision-dcgan/main.py index e8e58db3..94965b0c 100644 --- a/src/templates/template-vision-dcgan/main.py +++ b/src/templates/template-vision-dcgan/main.py @@ -170,7 +170,7 @@ def _(): if rank == 0: exp_logger.close() #::: } :::# - + # #::: if (it.save_training || it.save_evaluation) { :::# # show last checkpoint names logger.info( diff --git a/src/templates/template-vision-dcgan/trainers.py b/src/templates/template-vision-dcgan/trainers.py index 4d1f90df..20f71ea5 100644 --- a/src/templates/template-vision-dcgan/trainers.py +++ b/src/templates/template-vision-dcgan/trainers.py @@ -88,6 +88,7 @@ def train_function(engine: Union[Engine, DeterministicEngine], batch: Any): return metrics + # #::: if(it.deterministic) { :::# trainer = DeterministicEngine(train_function) #::: } else { :::# diff --git a/src/templates/template-vision-dcgan/utils.py b/src/templates/template-vision-dcgan/utils.py index 43941f5a..1e4de292 100644 --- a/src/templates/template-vision-dcgan/utils.py +++ b/src/templates/template-vision-dcgan/utils.py @@ -132,6 +132,8 @@ def setup_logging(config: Any) -> Logger: #::: if (it.save_training || it.save_evaluation || it.patience || it.terminate_on_nan || it.limit_sec) { :::# + + def setup_handlers( trainer: Engine, evaluator: Engine, diff --git a/src/templates/template-vision-segmentation/main.py b/src/templates/template-vision-segmentation/main.py index e1369882..48bcafe9 100644 --- a/src/templates/template-vision-segmentation/main.py +++ b/src/templates/template-vision-segmentation/main.py @@ -178,7 +178,7 @@ def _(): if rank == 0: exp_logger.close() #::: } :::# - + # #::: if (it.save_training || it.save_evaluation) { :::# # show last checkpoint names logger.info( diff --git a/src/templates/template-vision-segmentation/trainers.py b/src/templates/template-vision-segmentation/trainers.py index e262c864..247c02a1 100644 --- a/src/templates/template-vision-segmentation/trainers.py +++ b/src/templates/template-vision-segmentation/trainers.py @@ -43,6 +43,7 @@ def train_function(engine: Engine, batch: Any): engine.state.metrics = metric return metric + # #::: if(it.deterministic) { :::# trainer = DeterministicEngine(train_function) #::: } else { :::# diff --git a/src/templates/template-vision-segmentation/utils.py b/src/templates/template-vision-segmentation/utils.py index 7e74a0c2..7b5335e5 100644 --- a/src/templates/template-vision-segmentation/utils.py +++ b/src/templates/template-vision-segmentation/utils.py @@ -132,6 +132,8 @@ def setup_logging(config: Any) -> Logger: #::: if (it.save_training || it.save_evaluation || it.patience || it.terminate_on_nan || it.limit_sec) { :::# + + def setup_handlers( trainer: Engine, evaluator: Engine, From b2ec00e4c0f3ca9d2f2aaec503850a896932b541 Mon Sep 17 00:00:00 2001 From: ydcjeff <32727188+ydcjeff@users.noreply.github.com> Date: Thu, 3 Jun 2021 11:41:35 +0630 Subject: [PATCH 2/2] chore: add comment --- src/store.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/store.js b/src/store.js index 6ade5c93..fe570c2c 100644 --- a/src/store.js +++ b/src/store.js @@ -71,9 +71,12 @@ export function genCode() { } store.code[file] = ejs .render( + // replace `\s(s) or \n(s)#:::\s` + // with `#::: ` currentFiles[file].replace(/([\s\n]+#:::\s)/gi, '#::: '), store.config ) + // trim ` #` .replace(/\s{4}#$/gim, '') } if (isDev) {