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

torch.jit.Error: The following operation failed in the TorchScript interpreter #16

Closed
qiyea opened this issue Mar 7, 2022 · 2 comments

Comments

@qiyea
Copy link

qiyea commented Mar 7, 2022

Hi @peikexin9, I have finetuned a model by using the script ./command/finetune/finetune.sh.

get_embedding.py is modified as follows:

trex = TrexModel.from_pretrained(f'checkpoints/similarity',
                                 checkpoint_file='checkpoint_last.pt',
                                 data_name_or_path=f'data-bin/similarity')

When running python command/inference/get_embedding.py, I got an error.

Traceback (most recent call last):
  File "command/inference/get_embedding.py", line 52, in <module>
    emb0 = loaded(sample0_emb, features_only=True)[0]['features']
  File "/usr/local/miniconda3/envs/trex/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
torch.jit.Error: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript, serialized code (most recent call last):
  File "code/__torch__/fairseq/modules/trex_encoder.py", line 252, in forward
    else:
      pass
    ops.prim.RaiseException(_44)
    ~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    return _45
class ByteCombineCNN(Module):

Traceback of TorchScript, original code (most recent call last):
  File "/data/binVul/trex-main/fairseq/modules/trex_encoder.py", line 166, in forward

        if self.layernorm_embedding is not None:
            x = self.layernorm_embedding(x)
                ~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        x = self.dropout_module(x)
        if self.quant_noise is not None:
RuntimeError: This Python function is annotated to be ignored and cannot be run
@peikexin9
Copy link
Member

This is likely due to

# loaded = torch.jit.load('checkpoints/similarity/trex.ptc')
is trying to load the jit model saved by TorchScript, but it is not saved (by line 12 and 13). I have now commented that out and made line 15 temporarily available. Try again?

@qiyea
Copy link
Author

qiyea commented Mar 8, 2022

Nice. It works! Thanks.

@qiyea qiyea closed this as completed Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants