-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from JetBrains-Research/integrate_commode_utils
Integrate commode utils
- Loading branch information
Showing
69 changed files
with
1,407 additions
and
5,399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ __pycache__/ | |
*.py[cod] | ||
*$py.class | ||
|
||
data/ | ||
wandb/ | ||
notebooks/ | ||
outputs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from argparse import ArgumentParser | ||
from typing import cast | ||
|
||
import torch | ||
from commode_utils.common import print_config | ||
from omegaconf import DictConfig, OmegaConf | ||
|
||
from code2seq.data.path_context_data_module import PathContextDataModule | ||
from code2seq.model import Code2Class | ||
from code2seq.utils.common import filter_warnings | ||
from code2seq.utils.test import test | ||
from code2seq.utils.train import train | ||
|
||
|
||
def configure_arg_parser() -> ArgumentParser: | ||
arg_parser = ArgumentParser() | ||
arg_parser.add_argument("mode", help="Mode to run script", choices=["train", "test"]) | ||
arg_parser.add_argument("-c", "--config", help="Path to YAML configuration file", type=str) | ||
return arg_parser | ||
|
||
|
||
def train_code2class(config: DictConfig): | ||
filter_warnings() | ||
|
||
if config.print_config: | ||
print_config(config, fields=["model", "data", "train", "optimizer"]) | ||
|
||
# Load data module | ||
data_module = PathContextDataModule(config.data_folder, config.data, is_class=True) | ||
data_module.prepare_data() | ||
data_module.setup() | ||
|
||
# Load model | ||
code2class = Code2Class(config.model, config.optimizer, data_module.vocabulary) | ||
|
||
train(code2class, data_module, config) | ||
|
||
|
||
def test_code2class(config: DictConfig): | ||
filter_warnings() | ||
|
||
# Load data module | ||
data_module = PathContextDataModule(config.data_folder, config.data) | ||
data_module.prepare_data() | ||
data_module.setup() | ||
|
||
# Load model | ||
code2class = Code2Class.load_from_checkpoint(config.checkpoint, map_location=torch.device("cpu")) | ||
|
||
test(code2class, data_module, config.seed) | ||
|
||
|
||
if __name__ == "__main__": | ||
__arg_parser = configure_arg_parser() | ||
__args = __arg_parser.parse_args() | ||
|
||
__config = cast(DictConfig, OmegaConf.load(__args.config)) | ||
if __args.mode == "train": | ||
train_code2class(__config) | ||
else: | ||
test_code2class(__config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from argparse import ArgumentParser | ||
from typing import cast | ||
|
||
import torch | ||
from commode_utils.common import print_config | ||
from omegaconf import DictConfig, OmegaConf | ||
|
||
from code2seq.data.path_context_data_module import PathContextDataModule | ||
from code2seq.model import Code2Seq | ||
from code2seq.utils.common import filter_warnings | ||
from code2seq.utils.test import test | ||
from code2seq.utils.train import train | ||
|
||
|
||
def configure_arg_parser() -> ArgumentParser: | ||
arg_parser = ArgumentParser() | ||
arg_parser.add_argument("mode", help="Mode to run script", choices=["train", "test"]) | ||
arg_parser.add_argument("-c", "--config", help="Path to YAML configuration file", type=str) | ||
return arg_parser | ||
|
||
|
||
def train_code2seq(config: DictConfig): | ||
filter_warnings() | ||
|
||
if config.print_config: | ||
print_config(config, fields=["model", "data", "train", "optimizer"]) | ||
|
||
# Load data module | ||
data_module = PathContextDataModule(config.data_folder, config.data) | ||
data_module.prepare_data() | ||
data_module.setup() | ||
|
||
# Load model | ||
code2seq = Code2Seq(config.model, config.optimizer, data_module.vocabulary, config.train.teacher_forcing) | ||
|
||
train(code2seq, data_module, config) | ||
|
||
|
||
def test_code2seq(config: DictConfig): | ||
filter_warnings() | ||
|
||
# Load data module | ||
data_module = PathContextDataModule(config.data_folder, config.data) | ||
data_module.prepare_data() | ||
data_module.setup() | ||
|
||
# Load model | ||
code2seq = Code2Seq.load_from_checkpoint(config.checkpoint, map_location=torch.device("cpu")) | ||
|
||
test(code2seq, data_module, config.seed) | ||
|
||
|
||
if __name__ == "__main__": | ||
__arg_parser = configure_arg_parser() | ||
__args = __arg_parser.parse_args() | ||
|
||
__config = cast(DictConfig, OmegaConf.load(__args.config)) | ||
if __args.mode == "train": | ||
train_code2seq(__config) | ||
else: | ||
test_code2seq(__config) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.