Skip to content

Handle ValueError in model_utils (generation config)#25389

Closed
dbuos wants to merge 2 commits intohuggingface:mainfrom
dbuos:handle_error_loading
Closed

Handle ValueError in model_utils (generation config)#25389
dbuos wants to merge 2 commits intohuggingface:mainfrom
dbuos:handle_error_loading

Conversation

@dbuos
Copy link
Contributor

@dbuos dbuos commented Aug 8, 2023

What does this PR do?

Add error handling clause.

Fixes #25388

Who can review?

@gante

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick PR! It seems weird to intercept this error here. The problem seems to stem from an invalid generation config (or the exception is badly chosen) so maybe do another except with a different log: probably at warning level, telling the user the generation config is invalid so we go back to a default config.

What do you think!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@RonanKMcGovern
Copy link

yes, sounds good to do it at the warning level - important to fix soon as this is breaking all transformers usage of llama 2 (and perhaps other models).

@dbuos
Copy link
Contributor Author

dbuos commented Aug 8, 2023

Thanks for your quick PR! It seems weird to intercept this error here. The problem seems to stem from an invalid generation config (or the exception is badly chosen) so maybe do another except with a different log: probably at warning level, telling the user the generation config is invalid so we go back to a default config.

What do you think!

@sgugger Absolutely, that makes sense. I've made the necessary changes. I've added another except block with a warning level.

@dbuos dbuos force-pushed the handle_error_loading branch from ab51215 to cc012e2 Compare August 8, 2023 19:28
@dbuos dbuos force-pushed the handle_error_loading branch from cc012e2 to e859561 Compare August 8, 2023 20:28
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for iterating! Just waiting for a second look from @gante and we can merge this!

@gante
Copy link
Contributor

gante commented Aug 9, 2023

Uhmmm there are way more models out there with generation config issues than I thought 💔

It seems validation needs more thought, namely:

  1. We should be able to load incorrect files, but perhaps keep strictness at save time (to avoid perpetuating bad practices)
  2. At least during a transition phase, we must downgrade these exceptions to warnings.

@dbuos This change is something I'd like to avoid -- if we are not throwing exceptions, we should keep doing things the way we were using before, and not reset the generation config. I'm working on validation this week, so I'd like to take this one :) As such, I'm closing this PR.

(cc @sgugger)

@gante gante closed this Aug 9, 2023
@RonanKMcGovern
Copy link

ok @gante , will you roll back the latest update then to reverse the breaking changes for models like Llama 2? I was just running the model and same issue. I'm moving to use transformers 4.31 but it's not ideal having to hard code that.

@gante
Copy link
Contributor

gante commented Aug 9, 2023

@RonanKMcGovern Yeah, you will be able to run

from transformers import AutoModelForCausalLM
chk = 'meta-llama/Llama-2-7b-hf'

if __name__ == '__main__':
    model = AutoModelForCausalLM.from_pretrained(chk, load_in_4bit=True, device_map='auto')
    print("Loaded Ok")

and use the model without modifications or changes in behavior. You may see a bunch of new warnings guiding you towards correct generate parameterization, though ;)

@gante
Copy link
Contributor

gante commented Aug 9, 2023

@RonanKMcGovern apologies if my reaction was perceived as abrupt when closing this PR! Your prompt reaction to fix this issue was appreciated 🤗

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

Successfully merging this pull request may close these issues.

Llama2 models not loading (Using main branch)

5 participants