def search_word(self, instance, value): config.print_args(instance, value, args_name='instance', kwargs_name='value') res = config.dictionary.search_word(value) print('Search result: {}'.format(res)) # self.rv.data = [{'text':'{} - {}'.format(key, ' // '.join(value))} for key, value in res.items()] self.rv.data = config.recycleview_data_formatter(res) return None
type=float, default=0.0, help= "If null_score - best_non_null is greater than the threshold predict null." ) args = parser.parse_args() batch_size = args.num_nodes * args.gpu_num_per_node * args.batch_size_per_device eval_batch_size = args.num_nodes * args.gpu_num_per_node * args.eval_batch_size_per_device epoch_size = math.ceil(args.train_example_num / batch_size) num_eval_steps = math.ceil(args.eval_example_num / eval_batch_size) args.iter_num = epoch_size * args.num_epochs args.predict_batch_size = eval_batch_size configs.print_args(args) def SquadDecoder(data_dir, batch_size, data_part_num, seq_length, is_train=True): with flow.scope.placement("cpu", "0:0"): ofrecord = flow.data.ofrecord_reader(data_dir, batch_size=batch_size, data_part_num=data_part_num, random_shuffle=is_train, shuffle_after_epoch=is_train) blob_confs = {}
help="If null_score - best_non_null is greater than the threshold predict null.", ) args = parser.parse_args() batch_size = args.num_nodes * args.gpu_num_per_node * args.batch_size_per_device eval_batch_size = ( args.num_nodes * args.gpu_num_per_node * args.eval_batch_size_per_device ) device = flow.device(args.device) epoch_size = math.ceil(args.train_example_num / batch_size) num_eval_steps = math.ceil(args.eval_example_num / eval_batch_size) args.iter_num = epoch_size * args.num_epochs args.predict_batch_size = eval_batch_size config.print_args(args) def save_model(module: nn.Module, checkpoint_path: str, name: str): snapshot_save_path = os.path.join(checkpoint_path, f"snapshot_{name}") if not os.path.exists(checkpoint_path): os.makedirs(checkpoint_path) print(f"Saving model to {snapshot_save_path}") flow.save(module.state_dict(), snapshot_save_path) class SquadDecoder(nn.Module): def __init__(self, data_dir, batch_size, data_part_num, seq_length, is_train=True): super().__init__() self.is_train = is_train
from trainer import Trainer if __name__ == '__main__': if not args.debug_mode: import wandb wandb.init(project=args.project, name=args.name, tags=args.tags, config=args) train_data = dataset.MDB_Dataset('MusicDelta_80sRock') test_data = dataset.MDB_Dataset('MusicDelta_80sRock') else: train_data = dataset.MDB_Dataset('MusicDelta_80sRock') test_data = dataset.MDB_Dataset('MusicDelta_80sRock') print_args(args) # get_model if args.model_arc == 'CNN': model = CNN(hidden_channel_num=10, output_number=4) else: raise AssertionError model = model.to(args.device) optimizer = torch.optim.Adam(model.parameters(), lr=args.learning_rate) if not args.debug_mode: wandb.watch(model) trainer = Trainer(model, optimizer, args.device, args.debug_mode, args.test_per_epoch, args.num_epochs, args.weight_path,