Problems with running on CPU

#79
by IExist999 - opened

I am using the code below. There is no any errors or warns. Test.txt stays empty, but model downloads in .cache.

from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "google/gemma-2b-it"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
model.to("cpu")
input_text = "make an ASCII art."
inputs = tokenizer(input_text, return_tensors="pt").to("cpu")
outputs = model.generate(**inputs, max_length=200)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
with open("test.txt", "w", encoding="utf-8") as file:
    file.write(generated_text)

How??? Why???

Google org

Hi,
I executed the provided code on Colab, and it ran as expected, saving the output to the test.txt file. Please check out this gist for your reference.

Hi,
I ran locally on my laptop and it saved the output to test.txt without any issue:

make an ASCII art.

           /\ /|
          |||| |
           \ | \
       _ _ /  ()()
     /    \   =>*<=
   /|      \   /
   \|     /__| |
     \_____) \__)

Since the model is gated I assume you requested for access on the model's page and you've been authorized with your HF token.
You can also add these two lines to see what's going on while loading the model.

import transformers
transformers.logging.set_verbosity_info()

Hi,

I added the mentioned lines of code and executed them successfully as expected. transformers.logging.set_verbosity_info() helps to monitor, debug, and track your transformer-based models effectively by enabling more detailed logs. For further reference, please check the gist.

image.png

Thank you.

Sign up or log in to comment