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

Add Bottleneck T5 (e.g., thesephist/contra-bottleneck-t5-small-wikipedia) #360

Closed
keviddles opened this issue Oct 17, 2023 · 10 comments
Closed
Labels
custom code The model requires custom code (not in transformers library) new model Request a new model

Comments

@keviddles
Copy link

keviddles commented Oct 17, 2023

Name of the feature
I'd love to leverage https://huggingface.co/thesephist/contra-bottleneck-t5-small-wikipedia in the browser

It is not listed in the supported models above, though I have been able to convert it locally.

However, I can't import it in JS as I get t5 is not supported.

I guess my question is, is this lack of support because it can't be supported, or simply because it hasn't been implemented yet?

If the latter, I'd be happy to hack on this myself if it's something you think could be supported, though I'm not quite sure where to start. Is there a guide for contributors to contribute community models?

(Let me know if it's helpful to share the converted models, they're about 800mb)

Reason for request

I'd love to port this colab to Javascript: https://colab.research.google.com/drive/1CF5Lr1bxoAFC_IPX5I0azu4X8UDz_zp-?usp=sharing#scrollTo=1hwxFKZzFKn5

@keviddles keviddles added the enhancement New feature or request label Oct 17, 2023
@xenova
Copy link
Owner

xenova commented Oct 18, 2023

Hi there 👋 the t5 model type has been supported for quite a while, so you shouldn't be getting an error like that. Have you uploaded your models to the Hub already? If so, can you share the model ids?

When it comes to weird issues like that, it's usually because of outdated build tools (like create-react-app, or something). Could you share what tools and versions you are using?

@keviddles
Copy link
Author

Ah, interesting. I'll put a repo together and share it shortly

@keviddles
Copy link
Author

keviddles commented Oct 18, 2023

I uploaded a repository here (https://github.com/keviddles/contra-bottleneck-t5-demonstration), but I'm having trouble getting it to deploy to github pages. Will comment if I can get that working.

I think the issue is probably that I'm loading the model wrong. The code I'm using to load the model is:

  const modelPath = "thesephist/contra-bottleneck-t5-small-wikipedia";
  const tokenizer = await AutoTokenizer.from_pretrained(modelPath);
  const model = await AutoModelForCausalLM.from_pretrained(
    "thesephist/contra-bottleneck-t5-small-wikipedia"
  );

And that produces the error:

Uncaught (in promise) Error: Unsupported model type: t5
    at AutoModelForCausalLM.from_pretrained (models.js:3630:19)
    at async main (index.ts:14:17)

Alternatively, if I load the model with:

  const model = await T5PreTrainedModel.from_pretrained(
    "thesephist/contra-bottleneck-t5-small-wikipedia"
  );

I see:

Screenshot 2023-10-18 at 10 58 54

I started with the former command (using AutoModelForCausalLM) as I'm trying to translate from the original Python code here.

@keviddles
Copy link
Author

Have you uploaded your models to the Hub already? If so, can you share the model ids?

Oh, follow up question: must models be available on the Hub, or can they be available locally? I've only been trying locally, I didn't realize that they might need to be uploaded to the hub first.

@xenova
Copy link
Owner

xenova commented Oct 18, 2023

I uploaded a repository here (https://github.com/keviddles/contra-bottleneck-t5-demonstration), but I'm having trouble getting it to deploy to github pages. Will comment if I can get that working.

Thanks! At first glance, your usage looks correct. Could you just let me know which transformers.js version you have installed? We did previously have some issues with minification (which lead to a similar error message as the one you are seeing). Fortunately, those have been resolved now in 2.6.2

Oh, follow up question: must models be available on the Hub, or can they be available locally? I've only been trying locally, I didn't realize that they might need to be uploaded to the hub first.

No, you can use the models locally too 👍 I just wanted to test, so if you have them on the hub, it will be easier to see what the problem is :)

I assume you've already converted it to ONNX, right? (note that transformers.js can't load the model you have listed out-of-the-box, since it doesn't contain the ONNX weights + graph). See here for more information.

@keviddles
Copy link
Author

Could you just let me know which transformers.js version you have installed?

^2.6.2

No, you can use the models locally too 👍 I just wanted to test, so if you have them on the hub, it will be easier to see what the problem is :)

Gotcha, let me upload them to the hub so they're available for testing.

I assume you've already converted it to ONNX, right? (note that transformers.js can't load the model you have listed out-of-the-box, since it doesn't contain the ONNX weights + graph). See here for more information.

Yep, converted them and they seemed to convert fine.

@xenova
Copy link
Owner

xenova commented Oct 18, 2023

I think I know what the problem is: t5-models aren't generally used as causal LMs (decoder-only / text-generation)... Instead, they are seq2seq LMs (encoder-decoder / text2text-generation). However, the model you are working with is indeed a text-generation model, since they use custom modelling code to handle this.

self.model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True).to(self.device)

Also, optimum doesn't actually support exporting t5 models for text-generation (see here). Instead, it only supports text2text-generation. I would assume that it will export dummy encoder weights when you exported with optimum (even though you will only be using the decoder during inference). cc @fxmarty any ideas?

@keviddles
Copy link
Author

Ah, interesting feedback. So presumably, the exported model is not viable.

I uploaded the models here, if there's some easy way to tell whether it's viable or not: https://huggingface.co/keviddles/contra-bottleneck-t5-demonstration-onnx/tree/main

@xenova xenova changed the title [Feature request] thesephist/contra-bottleneck-t5-small-wikipedia Add Bottleneck T5 (e.g., thesephist/contra-bottleneck-t5-small-wikipedia) Dec 6, 2023
@xenova xenova added new model Request a new model and removed enhancement New feature or request labels Dec 6, 2023
@xenova
Copy link
Owner

xenova commented Dec 6, 2023

You may be able to export it to ONNX with custom configurations, a recent addition to the Optimum library. Also, since the "Bottleneck T5" architecture is custom code (built on top of HF transformers), it may be a good idea to make a feature request in the original transformers library too.

@xenova xenova added the custom code The model requires custom code (not in transformers library) label Dec 6, 2023
@keviddles
Copy link
Author

Thanks for the feedback, @xenova .

It'll probably be a while since I pick this back up, so I will close this issue for now. If others want to pick it up, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom code The model requires custom code (not in transformers library) new model Request a new model
Projects
None yet
Development

No branches or pull requests

2 participants