Australia/Sydney
BlogAugust 25, 2023

Install Code Llama on Your Local Machine - Step by Step Tutorial

Fahd Mirza

 Here is full step by step demo of how to install code llama by Meta on your local server in cloud or on laptop easily and quickly.




Commands Used:

!pip install transformers


!git clone https://github.com/PanQiWei/AutoGPTQ

cd AutoGPTQ

! git checkout a7167b1

!pip3 install .


from transformers import AutoTokenizer, pipeline, logging

from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig


model_name_or_path = "TheBloke/CodeLlama-7B-GPTQ"


use_triton = False


tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)


model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,

        use_safetensors=True,

        trust_remote_code=False,

        device="cuda:0",

        use_triton=use_triton,

        quantize_config=None)

prompt = "Write a bash script to delete all files older than 90 days with extension .log"

prompt_template=f'''{prompt}

'''


print("\ \ *** Generate:")


logging.set_verbosity(logging.CRITICAL)


print("*** Pipeline:")

pipe = pipeline(

    "text-generation",

    model=model,

    tokenizer=tokenizer,

    max_new_tokens=512,

    temperature=0.7,

    top_p=0.95,

    repetition_penalty=1.15

)


print(pipe(prompt_template)[0]['generated_text'])

Share this post:
On this page

Let's Partner

If you are looking to build, deploy or scale AI solutions — whether you're just starting or facing production-scale challenges — let's chat.

Subscribe to Fahd's Newsletter

Weekly updates on AI, cloud engineering, and tech innovations