def main(): """Main program.""" args = get_args() if args.num_layers_per_virtual_pipeline_stage is not None: print("Interleaved pipeline schedule is not yet supported for text generation.") exit() if args.task == 'LAMBADA': eval_metric = 'accuracy' elif args.task == 'WIKITEXT103': eval_metric = 'loss' else: raise NotImplementedError('{} task is not implemented.'.format( args.task)) # Set up model and load checkpoint. model = get_model(get_model_provider(eval_metric), wrap_with_ddp=False) if args.load is not None: _ = load_checkpoint(model, None, None) assert len(model) == 1, "Above condition should have caught this" model = model[0] # Data stuff. dataset = build_dataset(args.task) dataloader = build_data_loader(dataset, args.micro_batch_size, args.num_workers, drop_last=False) # Run evaluation. evaluate_and_print_results(args.task, dataloader, model, eval_metric) print_rank_0('done :-)')
def main(): """Main program.""" args = get_args() if args.task == 'LAMBADA': eval_metric = 'accuracy' elif args.task == 'WIKITEXT103': eval_metric = 'loss' else: raise NotImplementedError('{} task is not implemented.'.format( args.task)) # Set up model and load checkpoint. model = get_model(get_model_provider(eval_metric)) if args.load is not None: _ = load_checkpoint(model, None, None) # Data stuff. dataset = build_dataset(args.task) dataloader = build_data_loader(dataset, args.batch_size, args.num_workers, drop_last=False) # Run evaluation. evaluate_and_print_results(args.task, dataloader, model, eval_metric) print_rank_0('done :-)')
def __init__(self): args = get_args() self.embedding_size = args.hidden_size self.faiss_use_gpu = args.faiss_use_gpu self.evidence_embedder_obj = None self.evidence_dataset = None self.mips_index = None self.eval_dataset = None # Get Evidence (Wikipedia) dataset self.get_evidence_dataset() # Load query encoder checkpoint only_query_model = True if args.biencoder_shared_query_context_model: only_query_model = False model = get_model(lambda: biencoder_model_provider(only_query_model=\ only_query_model, biencoder_shared_query_context_model=\ args.biencoder_shared_query_context_model)) self.model = load_biencoder_checkpoint( model, only_query_model=only_query_model) assert len(self.model) == 1 self.model[0].eval() # Load faiss indexer self.faiss_wrapper()
def main(): """Main program.""" initialize_megatron(extra_args_provider=add_text_generate_args, args_defaults={ 'tokenizer_type': 'GPT2BPETokenizer', 'no_load_rng': True, 'no_load_optim': True }) args = get_args() if args.num_layers_per_virtual_pipeline_stage is not None: print( "Interleaved pipeline schedule is not yet supported for text generation." ) exit() # Set up model and load checkpoint. model = get_model(model_provider) if args.load is not None: _ = load_checkpoint(model, None, None) assert len(model) == 1, "Above condition should have caught this" model = model[0] # Generate samples. if args.num_samples == 0: args.micro_batch_size = 1 if args.sample_input_file != None: generate_samples_input_from_file(model) else: generate_samples_interactive(model) else: generate_and_write_samples_unconditional(model)
def load_attributes(self): """Load the necessary attributes: model, dataloader and empty BlockData""" model = get_model( lambda: general_ict_model_provider(only_block_model=True)) self.model = load_ict_checkpoint( model, only_block_model=True, from_realm_chkpt=self.using_realm_chkpt) self.model.eval() self.dataset = get_ict_dataset() self.dataloader = iter( get_one_epoch_dataloader(self.dataset, self.batch_size)) self.block_data = BlockData(load_from_path=False)
def main(): """Main program.""" initialize_megatron(extra_args_provider=add_text_generate_args, args_defaults={'tokenizer_type': 'GPT2BPETokenizer'}) # Set up model and load checkpoint. model = get_model(model_provider) args = get_args() if args.load is not None: _ = load_checkpoint(model, None, None) # Generate samples. if args.num_samples == 0: args.batch_size = 1 if args.sample_input_file != "": generate_samples_input_from_file(model) else: generate_samples_interactive(model) else: generate_and_write_samples_unconditional(model)
def load_attributes(self): """ Load the necessary attributes: model, dataloader and empty BlockData """ only_context_model = True if self.biencoder_shared_query_context_model: only_context_model = False model = get_model(lambda: biencoder_model_provider(only_context_model \ = only_context_model, biencoder_shared_query_context_model = \ self.biencoder_shared_query_context_model)) self.model = load_biencoder_checkpoint( model, only_context_model=only_context_model) assert len(self.model) == 1 self.model[0].eval() self.dataset = get_open_retrieval_wiki_dataset() self.dataloader = iter(get_one_epoch_dataloader(self.dataset, \ self.batch_size)) self.evidence_embedder_obj = OpenRetreivalDataStore( \ load_from_path=False)
def main(): args = get_args() if args.api_prompt: # obtain the generations by calling the api generate_samples_by_calling_api() return if args.num_layers_per_virtual_pipeline_stage is not None: print( "Interleaved pipeline schedule is not yet supported for text generation." ) exit() # Set up model and load checkpoint. model = get_model(model_provider, wrap_with_ddp=False) if args.load is not None: _ = load_checkpoint(model, None, None) assert len(model) == 1, "Above condition should have caught this" model = model[0] # perform the prompting generate_samples_by_prompting_input_from_file(model)
def main(): """Main program.""" drmode = 0 mode = 0 initialize_megatron(extra_args_provider=add_text_generate_args, args_defaults={'tokenizer_type': 'GPT2BPETokenizer'}) # Set up model and load checkpoint. model = get_model(model_provider) args = get_args() tokenizer = get_tokenizer() if args.load is not None: _ = load_checkpoint(model, None, None) # Generate samples. if drmode == 1: f = open("questions.txt", 'r') if mode == 0: dir = "qa_345M" else: dir = "qa_345M_ip" if drmode == 0: f = open("para.txt", 'r') if mode == 0: dir = "pa_345M" else: dir = "pa_345M_ip" qs = f.readlines() question_list = [] import json for i in qs: question_list.append(i) f.close() fdir = os.listdir() if not (dir in fdir): os.mkdir(dir) import random import jsonlines while True: q = random.choice(question_list) lists = os.listdir(dir) question = q lts = question[:20] + '.jsonl' if (lts in lists): continue #str=generate_token_tensor(str,tokenizer) if mode == 0: output_string = generate_one_text(model, tokenizer, args, question) print(question, output_string) text_dir = dir + "/" already = [] with jsonlines.open(text_dir + question[:20] + '.jsonl', mode='w') as writer: otc = {} otc['question'] = question otc['answer'] = output_string #print(otc) writer.write(otc) else: output_string, output_scores = generate_string( model, tokenizer, args, question) ranklist = np.argsort(output_scores) best_score = output_scores[ranklist[0]] text_dir = dir + "/" already = [] with jsonlines.open(text_dir + question[:20] + '.jsonl', mode='w') as writer: otc = {} otc['question'] = question otc['answer'] = output_string[ranklist[0]] #print(otc) writer.write(otc)
if __name__ == "__main__": initialize_megatron(extra_args_provider=add_text_generate_args, args_defaults={ 'tokenizer_type': 'GPT2BPETokenizer', 'no_load_rng': True, 'no_load_optim': True }) args = get_args() if args.num_layers_per_virtual_pipeline_stage is not None: print( "Interleaved pipeline schedule is not yet supported for text generation." ) exit() # Set up model and load checkpoint model = get_model(model_provider, wrap_with_ddp=False) if args.load is not None: _ = load_checkpoint(model, None, None) assert len(model) == 1, "Above condition should have caught this" model = model[0] if mpu.is_pipeline_first_stage() and mpu.get_tensor_model_parallel_rank( ) == 0: server = MegatronServer(model) server.run("0.0.0.0") while True: choice = torch.cuda.LongTensor(1) torch.distributed.broadcast(choice, 0) if choice[0].item() == 0: