Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'rerank' #2213

Closed
Bachstelze opened this issue Jun 5, 2020 · 2 comments
Closed

ImportError: cannot import name 'rerank' #2213

Bachstelze opened this issue Jun 5, 2020 · 2 comments
Assignees
Labels

Comments

@Bachstelze
Copy link

I executed examples/noisychannel/rerank_tune.py following the noisy channel example and get File "examples/noisychannel/rerank_tune.py", line 12, in <module> from . import rerank, rerank_options ImportError: cannot import name 'rerank' or

  File "examples/noisychannel/rerank_tune.py", line 93, in <module>
    cli_main()
  File "examples/noisychannel/rerank_tune.py", line 89, in cli_main
    random_search(args)
  File "examples/noisychannel/rerank_tune.py", line 60, in random_search
    best_lenpen, best_weight1, best_weight2, best_weight3, best_score = rerank.rerank(rerank_args)
  File "/media/kalle/Sprachdaten/noisy/fairseq/examples/noisychannel/rerank.py", line 262, in rerank
    rerank_score_lm.score_lm(args)
  File "/media/kalle/Sprachdaten/noisy/fairseq/examples/noisychannel/rerank_score_lm.py", line 44, in score_lm
    args.source_lang, prefix_len=args.prefix_len)
  File "/media/kalle/Sprachdaten/noisy/fairseq/examples/noisychannel/rerank_utils.py", line 619, in lm_scoring
    preprocess.main(input_args)
  File "/media/kalle/Sprachdaten/noisy/fairseq/fairseq_cli/preprocess.py", line 259, in main
    make_all(args.source_lang, src_dict)
  File "/media/kalle/Sprachdaten/noisy/fairseq/fairseq_cli/preprocess.py", line 241, in make_all
    make_dataset(vocab, args.trainpref, "train", lang, num_workers=args.workers)
  File "/media/kalle/Sprachdaten/noisy/fairseq/fairseq_cli/preprocess.py", line 237, in make_dataset
    make_binary_dataset(vocab, input_prefix, output_prefix, lang, num_workers)
  File "/media/kalle/Sprachdaten/noisy/fairseq/fairseq_cli/preprocess.py", line 169, in make_binary_dataset
    100 * sum(replaced.values()) / n_seq_tok[1],
ZeroDivisionError: division by zero
@sk-g
Copy link

sk-g commented Jun 10, 2020

Same thing,

Traceback (most recent call last):                                                                                                                                                     File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_09/examples/noisychannel/rerank_tune.py", line 12, in <module>                                                           
    from . import rerank, rerank_options                                                                                                                                             
ImportError: cannot import name 'rerank'        

Unfortunately, I could not get the noisy channel example to work with older release of fairseq (and pytorch), some other issue where a file was expected to be generated (I see that this was because the code was looking for hardcoded paths like root_dir + 'new_bpe' something like that.

STEP 4: score the translations for model 1                                                                                                                                           
STEP 4.5: language modeling for P(T)                                                                                                                                                 
Namespace(align_suffix=None, alignfile=None, bpe=None, cpu=False, criterion='cross_entropy', dataset_impl='mmap', destdir='/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/ex\
amples/noisychannel/rerank_data/wmt17/nbest_5_subset_valid_fw_name_fw_model_ex_shard_0_of_1/lm_preprocessed', empty_cache_freq=0, fp16=False, fp16_init_scale=128, fp16_scale_tolera\
nce=0.0, fp16_scale_window=None, generate_lattice=False, joined_dictionary=False, lattice_outdir=None, log_format=None, log_interval=1000, lr_scheduler='fixed', memory_efficient_fp\
16=False, min_loss_scale=0.0001, no_progress_bar=False, nwordssrc=-1, nwordstgt=-1, only_source=True, optimizer='nag', padding_factor=8, seed=1, source_lang=None, srcdict='/lustre/\
lustre4/users/sgouda//rerank_example/lm/dict.txt', target_lang=None, task='translation', tensorboard_logdir='', testpref=None, tgtdict=None, threshold_loss_scale=None, thresholdsrc\
=0, thresholdtgt=0, token_boosting_file=None, tokenizer=None, trainpref='/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_data/wmt17/nbest_5_subs\
et_valid_fw_name_fw_model_ex_shard_0_of_1/rescore_data_new_bpe.en', user_dir=None, validpref=None, workers=1)                                                                        
| [None] Dictionary: 35879 types                                                                                                                                                     
Traceback (most recent call last):                                                                                                                                                   
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_tune.py", line 87, in <module>                                                           
    cli_main()                                                                                                                                                                       
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_tune.py", line 83, in cli_main                                                           
    random_search(args)                                                                                                                                                              
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_tune.py", line 54, in random_search                                                      
    best_lenpen, best_weight1, best_weight2, best_weight3, best_score = rerank.rerank(rerank_args)                                                                                   
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank.py", line 259, in rerank                                                                 
    rerank_score_lm.score_lm(args)                                                                                                                                                   
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_score_lm.py", line 38, in score_lm                                                       
    args.source_lang, prefix_len=args.prefix_len)                                                                                                                                    
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_utils.py", line 614, in lm_scoring                                                       
    preprocess.main(input_args)                                                                                                                                                      
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/preprocess.py", line 245, in main                                                                                     
    make_all(args.source_lang, src_dict)                                                                                                                                             
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/preprocess.py", line 227, in make_all                                                                                 
    make_dataset(vocab, args.trainpref, "train", lang, num_workers=args.workers)                                                                                                     
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/preprocess.py", line 223, in make_dataset                                                                             
    make_binary_dataset(vocab, input_prefix, output_prefix, lang, num_workers)                                                                                                       
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/preprocess.py", line 109, in make_binary_dataset                                                                      
    offsets = Binarizer.find_offsets(input_file, num_workers)                                                                                                                        
  File "/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/fairseq/binarizer.py", line 73, in find_offsets                                                                       
    with open(filename, 'r', encoding='utf-8') as f:                                                                                                                                 
FileNotFoundError: [Errno 2] No such file or directory: '/nfs/mercury-12/u13/sandbox/fairseq/fairseq.2020_06_06/examples/noisychannel/rerank_data/wmt17/nbest_5_subset_valid_fw_name\
_fw_model_ex_shard_0_of_1/rescore_data_new_bpe.en'                                                                                                                                   
437.14user 60.29system 9:51.27elapsed 84%CPU (0avgtext+0avgdata 6542760maxresident)k                                                                                                 
11299670inputs+68064outputs (390major+2950235minor)pagefaults 0swaps                                                                                                                 
0.00user 0.02system 0:00.02elapsed 87%CPU (0avgtext+0avgdata 572maxresident)k                                                                                                        
0inputs+0outputs (0major+255minor)pagefaults 0swaps                                                                                                                                  
GENERIC JOB FOR   CRASHED AT  Sun Jun  7 11:33:48 2020                                                                                                                               
STATUS CODE  1                                                                                                                                                                       
                                                                                                                                                                                     
+++++++ newxg finished Sun Jun  7 11:33:48 2020 +++++++ 

So I decided to update the repos and give it another go. I am yet to check the code before doing which I wanted to see if this issue was mentioned here in the official repo.

Thanks

@Bachstelze
Copy link
Author

This issue is probably related to #2738

@myleott myleott added bug and removed documentation labels Oct 23, 2020
@myleott myleott mentioned this issue Oct 26, 2020
myleott added a commit that referenced this issue Oct 26, 2020
jinyiyang-jhu pushed a commit to jinyiyang-jhu/fairseq-jyang that referenced this issue Feb 26, 2021
Summary:
- Rename type -> key in fairseq/tasks/sentence_prediction.py (fixes facebookresearch/fairseq#2746)
- Update preprocessing docs (fixes facebookresearch/fairseq#2565)
- Turn off logging in test_fp16_optimizer.TestGradientScaling
- Documentation updates
- Remove some unused code
- Fix noisychannel example (fixes facebookresearch/fairseq#2213)

Pull Request resolved: facebookresearch/fairseq#2786

Reviewed By: shruti-bh

Differential Revision: D24515146

Pulled By: myleott

fbshipit-source-id: 86b0f5516c57610fdca801c60e58158ef052fc3a
facebook-github-bot pushed a commit that referenced this issue Aug 19, 2021
Summary:
Fix fairinternal/fairseq-py#2177 for the transformer conversion to Hydra.

The way the defaults are dealt with now is different so when you use the legacy Namespace configuration, you end up with a default encoder_embed_dim, which in the VGG case sets up a encoder attention in the TransformerDecoderLayer with the wrong dimentions.
The easiest solution is to erase the default value for encoder_embed_dim (by forcing it to None) when converting the VGG config to the raw Namespace for the decoder layer.

Tested with:
`pytest tests/speech_recognition/test_vggtransformer.py -k Transformer`

Pull Request resolved: fairinternal/fairseq-py#2213

Test Plan: pytest tests/speech_recognition/test_vggtransformer.py -k Transformer

Reviewed By: sshleifer

Differential Revision: D30425143

Pulled By: Mortimerp9

fbshipit-source-id: 92f6dea2ffbb68e441700bcc55274b3167a587b3
sorenmulli pushed a commit to sorenmulli/fairseq that referenced this issue Oct 4, 2021
…bookresearch#2213)

Summary:
Fix fairinternal/fairseq-py#2177 for the transformer conversion to Hydra.

The way the defaults are dealt with now is different so when you use the legacy Namespace configuration, you end up with a default encoder_embed_dim, which in the VGG case sets up a encoder attention in the TransformerDecoderLayer with the wrong dimentions.
The easiest solution is to erase the default value for encoder_embed_dim (by forcing it to None) when converting the VGG config to the raw Namespace for the decoder layer.

Tested with:
`pytest tests/speech_recognition/test_vggtransformer.py -k Transformer`

Pull Request resolved: fairinternal/fairseq-py#2213

Test Plan: pytest tests/speech_recognition/test_vggtransformer.py -k Transformer

Reviewed By: sshleifer

Differential Revision: D30425143

Pulled By: Mortimerp9

fbshipit-source-id: 92f6dea2ffbb68e441700bcc55274b3167a587b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants