llama README

The project's README from github.com/meta-llama/llama. As one markdown file: README.md.

Note of deprecation

Thank you for developing with Llama models. As part of the Llama 3.1 release, we’ve consolidated GitHub repos and added some additional repos as we’ve expanded Llama’s functionality into being an e2e Llama Stack. Please use the following repos going forward:

If you have any questions, please feel free to file an issue on any of the above repos and we will do our best to respond in a timely manner.

Thank you!

(Deprecated) Llama 2

We are unlocking the power of large language models. Llama 2 is now accessible to individuals, creators, researchers, and businesses of all sizes so that they can experiment, innovate, and scale their ideas responsibly.

This release includes model weights and starting code for pre-trained and fine-tuned Llama language models — ranging from 7B to 70B parameters.

This repository is intended as a minimal example to load Llama 2 models and run inference. For more detailed examples leveraging Hugging Face, see llama-cookbook.

Updates post-launch

See UPDATES.md. Also for a running list of frequently asked questions, see here.

Download

In order to download the model weights and tokenizer, please visit the Meta website and accept our License.

Once your request is approved, you will receive a signed URL over email. Then run the download.sh script, passing the URL provided when prompted to start the download.

Pre-requisites: Make sure you have wget and md5sum installed. Then run the script: ./download.sh.

Keep in mind that the links expire after 24 hours and a certain amount of downloads. If you start seeing errors such as 403: Forbidden, you can always re-request a link.

Access to Hugging Face

We are also providing downloads on Hugging Face. You can request access to the models by acknowledging the license and filling the form in the model card of a repo. After doing so, you should get access to all the Llama models of a version (Code Llama, Llama 2, or Llama Guard) within 1 hour.

Quick Start

You can follow the steps below to quickly get up and running with Llama 2 models. These steps will let you run quick inference locally. For more examples, see the Llama 2 cookbook repository.

  1. In a conda env with PyTorch / CUDA available clone and download this repository.

  2. In the top-level directory run:

    pip install -e .
    
  3. Visit the Meta website and register to download the model/s.

  4. Once registered, you will get an email with a URL to download the models. You will need this URL when you run the download.sh script.

  5. Once you get the email, navigate to your downloaded llama repository and run the download.sh script.

    • Make sure to grant execution permissions to the download.sh script
    • During this process, you will be prompted to enter the URL from the email.
    • Do not use the “Copy Link” option but rather make sure to manually copy the link from the email.
  6. Once the model/s you want have been downloaded, you can run the model locally using the command below:

torchrun --nproc_per_node 1 example_chat_completion.py \
    --ckpt_dir llama-2-7b-chat/ \
    --tokenizer_path tokenizer.model \
    --max_seq_len 512 --max_batch_size 6

Note

Inference

Different models require different model-parallel (MP) values:

Model MP
7B 1
13B 2
70B 8

All models support sequence length up to 4096 tokens, but we pre-allocate the cache according to max_seq_len and max_batch_size values. So set those according to your hardware.

Pretrained Models

These models are not finetuned for chat or Q&A. They should be prompted so that the expected answer is the natural continuation of the prompt.

See example_text_completion.py for some examples. To illustrate, see the command below to run it with the llama-2-7b model (nproc_per_node needs to be set to the MP value):

torchrun --nproc_per_node 1 example_text_completion.py \
    --ckpt_dir llama-2-7b/ \
    --tokenizer_path tokenizer.model \
    --max_seq_len 128 --max_batch_size 4

Fine-tuned Chat Models

The fine-tuned models were trained for dialogue applications. To get the expected features and performance for them, a specific formatting defined in chat_completion needs to be followed, including the INST and <<SYS>> tags, BOS and EOS tokens, and the whitespaces and breaklines in between (we recommend calling strip() on inputs to avoid double-spaces).

You can also deploy additional classifiers for filtering out inputs and outputs that are deemed unsafe. See the llama-cookbook repo for an example of how to add a safety checker to the inputs and outputs of your inference code.

Examples using llama-2-7b-chat:

torchrun --nproc_per_node 1 example_chat_completion.py \
    --ckpt_dir llama-2-7b-chat/ \
    --tokenizer_path tokenizer.model \
    --max_seq_len 512 --max_batch_size 6

Llama 2 is a new technology that carries potential risks with use. Testing conducted to date has not — and could not — cover all scenarios. In order to help developers address these risks, we have created the Responsible Use Guide. More details can be found in our research paper as well.

Issues

Please report any software “bug”, or other problems with the models through one of the following means:

Model Card

See MODEL_CARD.md.

License

Our model and weights are licensed for both researchers and commercial entities, upholding the principles of openness. Our mission is to empower individuals, and industry through this opportunity, while fostering an environment of discovery and ethical AI advancements.

See the LICENSE file, as well as our accompanying Acceptable Use Policy

References

  1. Research Paper
  2. Llama 2 technical overview
  3. Open Innovation AI Research Community

For common questions, the FAQ can be found here which will be kept up to date over time as new questions arise.

Original Llama

The repo for the original llama release is in the llama_v1 branch.

llama (meta-llama/llama)

Searching Database…

59.6K ·GitHub
这是什么?这是 Meta 的参考推理代码,用于在本地运行 Llama 2 语言模型(7B 到 70B 参数),可以加载预训练或经过对话微调的权重,并生成文本补全。
这是完整的应用,还是只是示例代码?这是一个极简的示例代码库,不是打包好的应用或服务器。你需要自己克隆仓库、加载权重,并直接调用 example_chat_completion.py 这类 Python 脚本。
怎样才能把模型跑起来?搭建一个带 PyTorch 和 CUDA 的 conda 环境,在 Meta 网站申请模型访问权限,然后用发到你邮箱的签名链接运行 './download.sh',最后用 torchrun 启动推理,并指定检查点目录和分词器。
运行之前我需要准备什么?一个带 PyTorch 和 CUDA 的 conda 环境,另外下载脚本还需要 'wget' 和 'md5sum',并且 GPU 数量要满足模型并行要求(7B、13B、70B 分别需要 1、2、8 块 GPU)。
这个仓库还适合用来使用 Llama 吗?不适合了。这个仓库已被弃用,Meta 把后续开发转移到了 llama-models、llama-toolchain、llama-agentic-system 和 llama-cookbook,所以这份代码现在只是旧版的极简示例。
我可以把权重用于商业用途吗?可以。Meta 同时向研究人员和商业机构授权该模型及其权重,但需遵守 LICENSE 文件和《可接受使用政策》(Acceptable Use Policy)。
我需要特定数量的 GPU 硬件吗?需要。不同规模的模型要求不同的模型并行(MP)GPU 数量:7B 需要 1 块,13B 需要 2 块,70B 需要 8 块。
预训练模型和对话模型有什么区别?预训练模型只会自然地续写文本,没有针对对话做调优;经过微调的对话模型则需要特定的 INST/BOS/EOS 提示格式,才能用于对话。
这些模型能处理多长的上下文?所有模型都支持最长 4096 个 token 的序列长度,但你需要根据硬件的显存来设置 max_seq_len 和 max_batch_size。
我能不用 download.sh,改从 Hugging Face 获取权重吗?可以。在 Meta 网站接受许可协议后,你也可以通过 Hugging Face 的模型卡片申请访问权限,通常一小时内就能获得访问。
现在应该改用什么?Meta 建议:权重和模型卡片用 llama-models,微调和安全相关用 llama-toolchain,智能体应用用 llama-agentic-system,社区示例用 llama-cookbook。
Creator
meta-llama
Size
1.1 MB
Stars
59.6K
Updated
CommitJan 26
Age
3y
Commits · 90 Days