# Running Llama model in Google colab

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%3E%5C
**Category:** Models\
**Created:** [September 4, 2024, 2:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288 "2024-09-04T14:44:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gencause](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@Gencause](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGencause)%5C
**Post date:** [September 4, 2024, 2:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%2F1 "2024-09-04T14:44:26Z")

</div>

Hi,

I’m trying to see a Llama 8B model demo in Google colab.

I just tried to run the following code in the colab prompt.

> **[meta-llama/Meta-Llama-3.1-8B-Instruct · Hugging Face](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

It ran into several errors.

I tried to fix using !pip install transformers[sentencepiece]  
or !pip install --upgrade transformers

but to no avail

Any help will be much appreciated.

NameError Traceback (most recent call last)  
 in \<cell line: 5\>()  
3 get\_ipython().system(‘pip install transformers[sentencepiece]’)  
4  
----\> 5 from transformers import pipeline  
6  
7 model\_id = “meta-llama/Meta-Llama-3.1-8B-Instruct”

4 frames  
/usr/local/lib/python3.10/dist-packages/torch/ **init**.py in   
762  
763 \_\_name, \_\_obj = ‘’, None  
 → 764 for \_\_name in dir(_C):  
765 if \_\_name[0] != '_’ and not \_\_name.endswith(‘Base’):  
766 **all**.append(\_\_name)

NameError: name ‘\_C’ is not defined

---

<div class="post-metadata">

**Author:** ![alice86](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@alice86](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Falice86)%5C
**Post date:** [September 5, 2024, 6:03am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%2F2 "2024-09-05T06:03:57Z")

</div>

Restarting the kernel will solve the problem, maybe

---

<div class="post-metadata">

**Author:** ![Gencause](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@Gencause](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGencause)%5C
**Post date:** [September 5, 2024, 7:16am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%2F3 "2024-09-05T07:16:53Z")

</div>

Hi,

Thanks for the suggestion. I tried restarting the kernel but it still doesn’t seem to work.

There’s another error in the following code snippet for text generation

# Use a pipeline as a high-level helper

from transformers import pipeline

messages = [  
{“role”: “user”, “content”: “Who are you?”},  
]  
pipe = pipeline(“text-generation”, model=“meta-llama/Meta-Llama-3.1-8B-Instruct”)  
pipe(messages)

I still get errors like

HTTPError Traceback (most recent call last)  
/usr/local/lib/python3.10/dist-packages/huggingface\_hub/utils/\_errors.py in hf\_raise\_for\_status(response, endpoint\_name)  
303 try:  
 → 304 response.raise\_for\_status()  
305 except HTTPError as e:

18 frames  
HTTPError: 401 Client Error: Unauthorized for url: [https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct/resolve/main/config.json](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct/resolve/main/config.json)

The above exception was the direct cause of the following exception:

GatedRepoError Traceback (most recent call last)  
GatedRepoError: 401 Client Error. (Request ID: Root=1-66d95297-65f74eaa1c17c1b55ae0ff7c;c1376837-e11c-4833-909c-9437d3f2b778)

Cannot access gated repo for url   
Access to model meta-llama/Meta-Llama-3.1-8B-Instruct is restricted. You must be authenticated to access it.

The above exception was the direct cause of the following exception:

OSError Traceback (most recent call last)  
/usr/local/lib/python3.10/dist-packages/transformers/utils/hub.py in cached\_file(path\_or\_repo\_id, filename, cache\_dir, force\_download, resume\_download, proxies, token, revision, local\_files\_only, subfolder, repo\_type, user\_agent, \_raise\_exceptions\_for\_gated\_repo, \_raise\_exceptions\_for\_missing\_entries, \_raise\_exceptions\_for\_connection\_errors, \_commit\_hash, \*\*deprecated\_kwargs)  
418 if resolved\_file is not None or not \_raise\_exceptions\_for\_gated\_repo:  
419 return resolved\_file  
 → 420 raise EnvironmentError(  
421 “You are trying to access a gated repo.\nMake sure to have access to it at "  
422 f"[https://huggingface.co/{path\_or\_repo\_id}.\n{str(e)}](https://huggingface.co/%7Bpath_or_repo_id%7D.%5Cn%7Bstr(e)%7D)”

OSError: You are trying to access a gated repo.  
Make sure to have access to it at   
401 Client Error. (Request ID: Root=1-66d95297-65f74eaa1c17c1b55ae0ff7c;c1376837-e11c-4833-909c-9437d3f2b778)

---

<div class="post-metadata">

**Author:** ![alice86](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@alice86](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Falice86)%5C
**Post date:** [September 5, 2024, 8:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%2F4 "2024-09-05T08:05:04Z")

</div>

I also meet the problem for the begin.  
You miss the token and you can go to the huggingface website → setting → Access Tokens

```auto
import os
os.environ['HF_TOKEN'] = 'my_value'

value = os.getenv('HF_TOKEN')
print(value) # my_value

```

---

<div class="post-metadata">

**Author:** ![Gencause](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@Gencause](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGencause)%5C
**Post date:** [September 5, 2024, 8:33am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%2F5 "2024-09-05T08:33:08Z")

</div>

Yeah…figured it out myself. Thanks. Works with token but additionally you need to request access to models and must be approved by the lllama forum .

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsystem)%5C
**Post date:** [September 5, 2024, 8:33pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Frunning-llama-model-in-google-colab%2F105288%2F6 "2024-09-05T20:33:10Z")

</div>

Closed on September 5, 2024, 8:33pm UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
