Llama 3

2 versions

The latest open source large language model released by Meta. The structure of this implementation of the model was inspired by Andrej Karpathy's llama.c, and originally written in Mojo by Aydyn Tairov. The model itself has been constructed from end to end using the MAX Graph API.

Text Generation
INT4
Transformer
Meta
Run with 1 command on desktop

Read the code and instructions, and run on desktop.

Llama 3

2 versions

The latest open source large language model released by Meta. The structure of this implementation of the model was inspired by Andrej Karpathy's llama.c, and originally written in Mojo by Aydyn Tairov. The model itself has been constructed from end to end using the MAX Graph API.

Text Generation
INT4
Transformer
Meta
Run with 1 command on desktop

Read the code and instructions, and run on desktop.

Llama 3.1

Language: Python

API: MAX Graph

This pipeline demonstrates text completion from an initial prompt using the Llama 3.1 large language model. The model itself has been constructed in Python using the MAX Graph API.

The MAX Graph API provides an accessible interface to the construction of flexible accelerated compute graphs, which are then optimized by the MAX Engine's advanced graph compiler. This pipeline showcases how a large language model can be fully defined using Python and MAX Graphs and then compiled for optimal inference performance via the MAX Engine.

Model

Llama 3.1 is an open source large language model released by Meta. The structure of this implementation was inspired by Andrej Karpathy's llama2.c and its Mojo port by Aydyn Tairov.

The text completion demo is compatible with the the official Llama 3 text completion demo.

The default settings for this pipeline use the 8B set of pretrained weights in q4_k quantized encodings.

Usage

  1. Install MAX:

    If MAX is not already installed, follow the installation instructions to set it up on your system.

  2. Clone the MAX examples repository:

    If you don't already have a local clone of this repository, create one via:

    git clone https://github.com/modularml/max.git
    

    The following instructions assume that you're present within this pipeline's directory, and you can change to it after cloning:

    cd max/pipelines/python/
    
  3. Run the text completion demo:

    On first execution, the tokenizer library and model weights will be downloaded and placed in a local .cache/ directory in your current path. The model will then be compiled and text completion will begin from the specified prompt.

    All of the pipelines have been configured to use a common driver, located in the directory hosting all MAX Graph examples. Assuming you're starting at the path of this README, the command invocation will look like:

    python3 pipelines.py llama3 --prompt "I believe the meaning of life is"
    

Options

The following command-line options are available to customize operation of the pipeline:

  • --max-length: Controls the maximum length of the text sequence (includes the input tokens). (Default value: 512)
  • --max-new-tokens: The maximum number of new tokens to generate. If a -1 value is provided, the model will continue to generate tokens for the entire context length. (Default value: -1) --model-path to specify locally downloaded full-precision weights for use in the model. Valid values: q4_0, q4_k, q6_k, float32. (Default value: float32).
  • --prompt: The text prompt to use for further generation.
  • --quantization-encoding: The encoding to use for a datatype that can be quantized to a low bits per weight format. The options for quantized formats will download and cache default weights, but float32 requires the use of
  • --serialized-model-path: If specified, tries to load a serialized model from this path.
  • --version: Selects which version in the Llama 3 family to use. Valid values: 3, 3.1. (Default value: 3.1)
  • --weight-path: Overrides the default URL, and allows for an already-downloaded pretrained weight file to be used with the model.

@ Copyright - Modular Inc - 2024