# Model with Genrate method to torchscript

**URL:** <https://discuss.huggingface.co/t/model-with-genrate-method-to-torchscript/143530>\
**Category:** Models\
**Created:** [March 1, 2025, 9:32am UTC](https://discuss.huggingface.co/t/model-with-genrate-method-to-torchscript/143530 "2025-03-01T09:32:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsmax](https://avatars.discourse-cdn.com/v4/letter/i/9fc29f/32.png) [@itsmax](https://discuss.huggingface.co/u/itsmax)\
**Post date:** [March 1, 2025, 9:32am UTC](https://discuss.huggingface.co/t/model-with-genrate-method-to-torchscript/143530/1 "2025-03-01T09:32:11Z")

</div>

I’ve been trying to export the MusicGen model to TorchScript with the problem. This model uses generate() method, which could not be converted directly to TorchScript to get results,. I searched for many websites but hadn’t found any solutions to solve this. Does anyone have solutions to cope with? I only have a mind that I have to separate all structures and convert them separately.  
I am trying to do this because I will continue to deploy this model to iOS and Andriod.  
Maybe I have to found a better model ☹

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [March 1, 2025, 10:49am UTC](https://discuss.huggingface.co/t/model-with-genrate-method-to-torchscript/143530/2 "2025-03-01T10:49:33Z")

</div>

There are also means such as the ONNX and GGUF formats.

> [@Generate without using the generate method](https://discuss.huggingface.co/t/generate-without-using-the-generate-method/11379):
>
> Posting this here for visibility. What if you want to decode the output of a generative seq2seq model (like T5, BART, etc.) yourself, without using the .generate() method? The code example below illustrates this. Suppose that the model is given a long text, for which it needs to generate a summary. We illustrate here how to manually decode the generated ids autoregressively. In each iteration, we add the predicted token id by the model to the decoder\_input\_ids, which are then fed as input to th…

> **[How to convert your PyTorch model to TorchScript](https://djl.ai/docs/pytorch/how_to_convert_your_model_to_torchscript.html)**
>
> An Engine-Agnostic Deep Learning Framework in Java

> **[Common AI Model Formats](https://huggingface.co/blog/ngxson/common-ai-model-formats)**
>
> A Blog post by Xuan-Son Nguyen on Hugging Face

---

<div class="post-metadata">

**Author:** ![itsmax](https://avatars.discourse-cdn.com/v4/letter/i/9fc29f/32.png) [@itsmax](https://discuss.huggingface.co/u/itsmax)\
**Post date:** [March 12, 2025, 3:24pm UTC](https://discuss.huggingface.co/t/model-with-genrate-method-to-torchscript/143530/3 "2025-03-12T15:24:02Z")

</div>

New updates! Although, I have not found a way to convert Generate, I found a way to self-implement the Generate Function, which means it could be implemented in other forms
