yukiarimo / yuna-ai

Your Private Companion. The future AGI takeover starts here!
https://www.yuna-ai.live/
GNU Affero General Public License v3.0
90 stars 11 forks source link

Emotional Model Torch Error #86

Closed kleywinn closed 2 months ago

kleywinn commented 2 months ago

Hi I'm having a hard time running yuna-ai. This is the log I'm getting when running python3 index.py:

It seems like torch is in the wrong version (from what I checked it's 2.2.2. And I'm using python 3.8.

Using device: mps
Traceback (most recent call last):
  File "index.py", line 208, in <module>
    yuna_server = YunaServer()
  File "index.py", line 35, in __init__
    self.chat_generator = ChatGenerator(self.config)
  File "/Users/kleywinn/Documents/yuna-ai/lib/generate.py", line 19, in __init__
    self.classifier = pipeline("text-classification", model=f"{config['server']['agi_model_dir']}yuna-emotion")
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/pipelines/__init__.py", line 905, in pipeline
    framework, model = infer_framework_load_model(
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/pipelines/base.py", line 292, in infer_framework_load_model
    raise ValueError(
ValueError: Could not load model lib/models/agi/yuna-emotion with any of the following classes: (<class 'transformers.models.auto.modeling_auto.AutoModelForSequenceClassification'>, <class 'transformers.models.roberta.modeling_roberta.RobertaForSequenceClassification'>). See the original errors:

while loading with AutoModelForSequenceClassification, an error is thrown:
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 532, in load_state_dict
    return torch.load(
  File "/opt/homebrew/lib/python3.8/site-packages/torch/serialization.py", line 1005, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/opt/homebrew/lib/python3.8/site-packages/torch/serialization.py", line 457, in __init__
    super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 541, in load_state_dict
    if f.read(7) == "version":
  File "/opt/homebrew/Cellar/python@3.8/3.8.19/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/pipelines/base.py", line 279, in infer_framework_load_model
    model = model_class.from_pretrained(model, **kwargs)
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py", line 563, in from_pretrained
    return model_class.from_pretrained(
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 3335, in from_pretrained
    state_dict = load_state_dict(resolved_archive_file)
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 553, in load_state_dict
    raise OSError(
OSError: Unable to load weights from pytorch checkpoint file for 'lib/models/agi/yuna-emotion/pytorch_model.bin' at 'lib/models/agi/yuna-emotion/pytorch_model.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

while loading with RobertaForSequenceClassification, an error is thrown:
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 532, in load_state_dict
    return torch.load(
  File "/opt/homebrew/lib/python3.8/site-packages/torch/serialization.py", line 1005, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/opt/homebrew/lib/python3.8/site-packages/torch/serialization.py", line 457, in __init__
    super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 541, in load_state_dict
    if f.read(7) == "version":
  File "/opt/homebrew/Cellar/python@3.8/3.8.19/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/pipelines/base.py", line 279, in infer_framework_load_model
    model = model_class.from_pretrained(model, **kwargs)
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 3335, in from_pretrained
    state_dict = load_state_dict(resolved_archive_file)
  File "/opt/homebrew/lib/python3.8/site-packages/transformers/modeling_utils.py", line 553, in load_state_dict
    raise OSError(
OSError: Unable to load weights from pytorch checkpoint file for 'lib/models/agi/yuna-emotion/pytorch_model.bin' at 'lib/models/agi/yuna-emotion/pytorch_model.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.
yukiarimo commented 2 months ago
  1. How did you install the torch?
  2. Are you using conda?
  3. What is your machine and OS?
  4. Have you installed all of the requirements (especially transformers)?
  5. As a hotfix, in the lib/generate.py

replace this line: self.classifier = pipeline("text-classification", model=f"{config['server']['agi_model_dir']}yuna-emotion")

With just: self.classifier = ""

kleywinn commented 2 months ago
  1. I used pip3 install torch
  2. No, I installed python via brew as a matter of fact I'm using the commands python3.8 and pip3.8 to specify the version.
  3. MacOS M1 Sonoma
  4. I believe so, at least everything from the installation suite.
  5. I did and it works, but I'm getting an error in the messaging response due to the lack of classifier
    File "/Users/kleywinn/Documents/yuna-ai/lib/generate.py", line 77, in generate
    response_add = self.classifier(response)[0]['label']
    TypeError: 'str' object is not callable
yukiarimo commented 2 months ago
  1. The official command is pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu (better to use that for more features)
  2. Even if it works for you, I'll highly recommend installing Anaconda, creating a virtual (condo's) environment, and then doing your stuff!
  3. Glad to hear that!
  4. Yeah, I see.
  5. So, why not to just disable emotions in the static/config.json?!
kleywinn commented 2 months ago

Ok, I'll give it a try with Anaconda. I disabled emotions and it worked indeed! I'm closing this issue for now. Thanks for the assistance.