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

KeyError when loading Mistral 7b via Transformers #713

Closed
lachlancahill opened this issue Mar 22, 2024 · 11 comments · Fixed by #740
Closed

KeyError when loading Mistral 7b via Transformers #713

lachlancahill opened this issue Mar 22, 2024 · 11 comments · Fixed by #740

Comments

@lachlancahill
Copy link

The bug
attempting to load the model yields the following output:

Loading checkpoint shards: 100%|██████████| 3/3 [00:06<00:00,  2.09s/it]
Traceback (most recent call last):
  File "C:\Users\lachl\PycharmProjects\llm_feedback_analytics\guidance_error.py", line 8, in <module>
    mistral = models.Transformers(model_id, echo=False, device_map=device, torch_dtype=torch.bfloat16)
  File "C:\Users\lachl\PycharmProjects\llm_feedback_analytics\.venv\lib\site-packages\guidance\models\transformers\_transformers.py", line 196, in __init__
    TransformersEngine(model, tokenizer, compute_log_probs, **kwargs),
  File "C:\Users\lachl\PycharmProjects\llm_feedback_analytics\.venv\lib\site-packages\guidance\models\transformers\_transformers.py", line 101, in __init__
    TransformersTokenizer(model, tokenizer),
  File "C:\Users\lachl\PycharmProjects\llm_feedback_analytics\.venv\lib\site-packages\guidance\models\transformers\_transformers.py", line 36, in __init__
    reconstructed += bytes([byte_decoder[c] for c in t.convert_ids_to_tokens(id)])
  File "C:\Users\lachl\PycharmProjects\llm_feedback_analytics\.venv\lib\site-packages\guidance\models\transformers\_transformers.py", line 36, in <listcomp>
    reconstructed += bytes([byte_decoder[c] for c in t.convert_ids_to_tokens(id)])
KeyError: '▁'

To Reproduce

import torch
from guidance import models

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

model_id = "mistralai/Mistral-7B-Instruct-v0.2"

mistral = models.Transformers(model_id, echo=False, device_map=device, torch_dtype=torch.bfloat16)

System info (please complete the following information):

  • OS: Windows 11
  • Guidance Version (guidance.__version__): 0.1.13
@riedgar-ms
Copy link
Collaborator

I can reproduce this. @slundberg is this another aspect of the unicode error you pushed a fix for earlier this week?

@riedgar-ms
Copy link
Collaborator

I believe that this is at least part of what is going wrong in #716

@JosephGatto
Copy link

Any update on this? Also getting same error. On Google Colab.

@riedgar-ms
Copy link
Collaborator

I've not heard from @slundberg who knows most about this. I've just started prodding it again

@riedgar-ms
Copy link
Collaborator

riedgar-ms commented Mar 28, 2024

As a work around @JosephGatto and @lachlancahill , it does appear that if you load mistral via llama-cpp (there is code for this in #716 ), it works.

riedgar-ms added a commit that referenced this issue Mar 30, 2024
Since our notebooks feature Mistral, add an example to our test matrix. The Mistral model itself is loaded via llama-cpp. However:

- Due to #713, have to skip loading Mistral via `transformers`
- To avoid running out of disk space on the GitHub runner machines, we have to narrow the testing in `test_transformers.py`
@MikoAL
Copy link

MikoAL commented Mar 31, 2024

I get this issue no matter what model I'm using, even if it was not based on mistral, any fixes?

@MikoAL
Copy link

MikoAL commented Mar 31, 2024

After a bit of testing, I switched to the commit where the version number was 0.1.12, the same error happened, switched to the commit where the version number was 0.1.11, and it started working again?

@talglobus
Copy link

Running into this issue as well, on a model finetuned from Mistral, loaded directly from pytorch

@lachlancahill
Copy link
Author

lachlancahill commented Apr 12, 2024

This issue has not been resolved I'm afraid. I have force-reinstalled from git and still get the same error.

@amirabdullah19852020
Copy link

Yes, this should still be open. I'm running into this error too on latest version.

@akshaymg99
Copy link

Running into the same error, with latest version

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 a pull request may close this issue.

7 participants