Integrating a Hugging Face Model with Google Colab
Indrajit S.
Senior Data Scientist @ Citi | GenAI | Kaggle Competition Expert | PHD research scholar in Data Science
Integrating models from Hugging Face with Google Colab.
Install Hugging Face Transformers
!pip install transformers
!pip install accelerate
!pip install bitsandbytes
Authenticate with Hugging Face
Authenticate in Colab:
from huggingface_hub import login
login(token="YOUR_HUGGING_FACE_TOKEN")
Load the Model and Tokenizer: Take an example we are trying to use gpt2 model.
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)