fix HF integration

#1
by not-lain - opened

this will fix the configuration problem you can test this pr before merging using the following code

from transformers import AutoModelForSequenceClassification
# the revision parameter is only temporary and it should be removed after this pr is merged
# this will also fix the code snippet for the model
model = AutoModelForSequenceClassification.from_pretrained("KhaldiAbderrhmane/emotion-classifier-hubert",trust_remote_code = True,revision="refs/pr/1")

@KhaldiAbderrhmane this pr can be further optimized (optional) by removing the from_pretrained from the __init__ method which i will handle in another pr once this one is merged.
if you have any other questions or feedback do not hesitate to reach back.

KhaldiAbderrhmane changed pull request status to merged

Man idk how many hours you saved from my life with your help, but got a question, how does this library works when it loads a model with AutoModel, i mean yes config is the config of that model that will be passed to the model, but what are the conventions that should be respected and how it works ?

@KhaldiAbderrhmane
config is considered a dataclass/attribute/init parameters all at the same time
when using AutoModelForxx.from_pretrained this will check if the repo has config.json there then load the parameters from there, after that it will use these parameters to instantiate the model, then it will download and inject the weights for you automatically.

TLDR;
instantiate the model and inject the weights for you.

once this is done you can use the model the same way you have been using

That's amazing actually how the library is built, i tried to read the documentation but felt like they're skipping a lot of details, do you recommend for me any resource, i really wanna have a portion of your knowledge, it's just amazing lol i can't hide it am super impressed by those lights of the open source deployment world

but what are the conventions that should be respected and how it works ?

there are few like the one about using model_type = "something" or inheriting from PretrainedSomething when setting the architecture.

for best practices, it is recommended you avoid using from_pretrained or any forms of loading inside the init method since the is done automatically outside when calling AutoModel.from_pretrained

but technically there are no other rules around the architecture only init, inheritance, model_type and config_class, as long as these have been respected, everything else is yours to change.
as for the init thingy, it is only an optimization and not a rule, i'll create a pr in a model which will explain what i mean

Got it, that's the main things i have to consider

there are no other rules around the architecture only init, inheritance, model_type and config_class, as long as these have been respected, everything else is yours to change.

Will be happily waiting for your pr, again no more thanks are enough, really appreciated your help.

thanks Abderrhmane 🙌

Sign up or log in to comment