Make sure that your python version >= 3.10, and you are on a cuda enabled device. Make a…
- User
Make sure that your python version >= 3.10, and you are on a cuda enabled device. Make a virtual environment on your machine and activate it. $python3 -m venv VENV_NAME source VENV_NAME/bin/activate #./VENV_NAME/scripts/activate if you are on Windows Call the following: pip install gptfast Copy the following code into a python file: import os import torch from transformers import AutoModelForCausalLM, AutoTokenizer from GPTFast.Core import gpt_fast from GPTFast.Helpers import timed
torch._dynamo.reset() os.environ["TOKENIZERS_PARALLELISM"] = "false"
device = "cuda" if torch.cuda.is_available() else "cpu"
def argmax(self, probabilities): # Use argmax to get the token with the maximum probability max_prob_index = torch.argmax(probabilities, dim=-1) return max_prob_index.unsqueeze(0)
model_name = "gpt2-xl" draft_model_name = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_name) initial_string = "Write me a short story." input_tokens = tokenizer.encode(initial_string, return_tensors="pt").to(device)
N_ITERS=10 MAX_TOKENS=50
gpt_fast_model = gpt_fast(model_name, draft_model_name=draft_model_name, sample_function=argmax) gpt_fast_model.to(device)
fast_compile_times = [] for i in range(N_ITERS): with torch.no_grad(): res, compile_time = timed(lambda: gpt_fast_model.generate(cur_tokens=input_tokens, max_tokens=MAX_TOKENS, speculate_k=6)) fast_compile_times.append(compile_time) print(f"gpt fast eval time {i}: {compile_time}") print("~" * 10) Run it and watch the magic 🪄! how to run it in kaggle
- Assistant
- User
- Assistant
It appears that there has been an error while installing
gptfastdue to a problem with thepyyamlpackage dependency. Specifically, the error suggests thatpyyaml==5.3.1is unable to be installed.To address this issue, try installing
pyyamlat a different version that is compatible with your environment, and then attempt to installgptfastagain. Here's how you can do it within a Kaggle notebook:-
Install a compatible version of
pyyaml, preferably a later version. You can install it directly using the following command:
-
- User
steps?
- Assistant
Sorry for any confusion earlier. Here's a step-by-step guide to attempt resolving the installation issue with
gptfaston a Kaggle notebook:-
Open your Kaggle Notebook.
-
Enable GPU acceleration:
- Click on the "Settings" tab in the notebook panel.
- Select the "Accelerator" dropdown and choose "GPU."
-
Install a compatible version of : In a new code cell, run the following:
-
- User
- Assistant
From the error message, it looks like there is a compatibility issue with the version of
pyyamlthatgptfastis trying to install (pyyaml==5.3.1) and the Python version in your environment.Given that
pyyaml==5.3.1seems to be causing the issue and you already havepyyamlinstalled (6.0.1), you can try to installgptfastwithout itspyyamldependency. You can do this by using the--no-depsflag withpipto ignore all dependencies. Here's how to attempt this:!pip install --no-deps gptfastThis will skip the installation of
pyyaml==5.3.1as well as all other dependencies (which seem to be already satisfied or available in your environment). As a result, you will only install thegptfastpackage.If functions correctly without , then you should be good to go. However, if it does require that exact version to function, then this solution may not work, and you might be unable to use in the current Kaggle environment.