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

Just one decoder.onnx #1

Open
Pengjie-W opened this issue May 24, 2024 · 1 comment
Open

Just one decoder.onnx #1

Pengjie-W opened this issue May 24, 2024 · 1 comment

Comments

@Pengjie-W
Copy link

Can I just use one decoder.onnx instead of one decoder.onnx and decoder_with_past.onnx? It takes up more space. If possible, can you modify and provide a version of the code. Thank you very much.

@ambroiseb
Copy link
Collaborator

Hello @Pengjie-W,
If I am not wrong, using a single decoder makes the inference much slower. I am not sure to make another version for this very soon, so I suggest you the following workaround.
You can overload the class OnnxPredictor and remove the lines involving decoder_with_past and adapt the generating loop. For example, you can replace the lines

            if past_key_values is None:
                out_decoder = self.decoder.run(None, {'input_ids': input_ids, 'encoder_hidden_states': out_encoder})
                logits = out_decoder[0]
                past_key_values = {'past_key_value_input_' + str(k): out_decoder[k + 1] for k in
                                   range(len(out_decoder[1:]))}

            else:
                out_decoder = self.decoder_with_past.run(None, {'input_ids': input_ids[:, -1:],
                                                                                **past_key_values})
                logits = out_decoder[0]
                past_key_values = {'past_key_value_input_' + str(i): pkv for i, pkv in enumerate(out_decoder[1:])}

with

            out_decoder = self.decoder.run(None, {'input_ids': input_ids, 'encoder_hidden_states': out_encoder})
            logits = out_decoder[0]

Then delete the file decoder_with_past.onnx.
Hope it helps you.
Greetings,
Ambroise

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