如何使用 ghs 运行 llama b bf

lambda 实验室现在推出 gh200 半价优惠,以让更多人习惯 arm 工具。这意味着您实际上可能有能力运行最大的开源模型!唯一需要注意的是,您有时必须从源代码构建一些东西。以下是我如何让 llama 405b 在 gh200s 上高精度运行。

创建实例

llama 405b 约为 750gb,因此您需要大约 10 个 96gb gpu 来运行它。 (gh200 具有相当好的 cpu-gpu 内存交换速度——这就是 gh200 的全部意义——所以你可以使用少至 3 个。每个令牌的时间会很糟糕,但总吞吐量是可以接受的,如果您正在执行批处理。)登录 lambda 实验室并创建一堆 gh200 实例。 确保为它们提供相同的共享网络文件系统。

lambda labs screenshot

将 ip 地址保存到 ~/ips.txt。

批量 ssh 连接助手

我更喜欢直接 bash 和 ssh,而不是 kubernetes 或 slurm 等任何花哨的东西。借助一些助手即可轻松管理。

# skip fingerprint confirmationfor ip in $(cat ~/ips.txt); do    echo "doing $ip"    ssh-keyscan $ip >> ~/.ssh/known_hostsdonefunction run_ip() {    ssh -i ~/.ssh/lambda_id_ed25519 ubuntu@$ip -- stdbuf -ol -el bash -l -c "$(printf "%q" "$*")"  /dev/null}function runall() { ips="$(cat ~/ips.txt)" run_ips "$@"; }function runrest() { ips="$(tail -n+2 ~/ips.txt)" run_ips "$@"; }function ssh_k() {    ip=$(sed -n "$k"p ~/ips.txt)    ssh -i ~/.ssh/lambda_id_ed25519 ubuntu@$ip}alias ssh_head='k=1 ssh_k'function killall() {    pkill -ife '.ssh/lambda_id_ed25519'    sleep 1    pkill -ife -9 '.ssh/lambda_id_ed25519'    while [[ -n "$(jobs -p)" ]]; do fg || true; done}

设置 nfs 缓存

我们将把 python 环境和模型权重放在 nfs 中。如果我们缓存它,加载速度会快得多。

# first, check the nfs works.# runall ln -s my_other_fs_name sharedrunhead 'echo world > shared/hello'runall cat shared/hello# install and enable cachefilesdrunall sudo apt-get updaterunall sudo apt-get install -y cachefilesdrunall "echo 'run=yescache_tag=mycachecache_backend=path=/var/cache/fscachecachefs_reclaim=0' | sudo tee -a /etc/default/cachefilesd"runall sudo systemctl restart cachefilesdrunall 'sudo journalctl -u cachefilesd | tail -n2'# set the "fsc" option on the nfs mountrunhead cat /etc/fstab # should have mount to ~/sharedrunall cp /etc/fstab etc-fstab-bak.txtrunall sudo sed -i 's/,proto=tcp,/,proto=tcp,fsc,/g' /etc/fstabrunall cat /etc/fstab# remountrunall sudo umount /home/ubuntu/wash2runall sudo mount /home/ubuntu/wash2runall cat /proc/fs/nfsfs/volumes # fsc column should say "yes"# test cache speeduprunhead dd if=/dev/urandom of=shared/bigfile bs=1m count=8192runall dd if=shared/bigfile of=/dev/null bs=1m # first one takes 8 secondsrunall dd if=shared/bigfile of=/dev/null bs=1m # seond takes 0.6 seconds

创建conda环境

我们可以在 nfs 中使用 conda 环境,并只用头节点来控制它,而不是在每台机器上小心地执行完全相同的命令。

# we'll also use a shared script instead of changing ~/.profile directly.# easier to fix mistakes that way.runhead 'echo ". /opt/miniconda/etc/profile.d/conda.sh" >> shared/common.sh'runall 'echo "source /home/ubuntu/shared/common.sh" >> ~/.profile'runall which conda# create the environmentrunhead 'conda create --prefix ~/shared/311 -y python=3.11'runhead '~/shared/311/bin/python --version' # double-check that it is executablerunhead 'echo "conda activate ~/shared/311" >> shared/common.sh'runall which python

安装阿芙罗狄蒂依赖项

aphrodite 是 vllm 的一个分支,启动速度更快,并且有一些额外的功能。
它将运行兼容 openai 的推理 api 和模型本身。

你需要手电筒、triton 和闪光注意。
您可以从 pytorch.org 获取 aarch64 torch 构建(您不想自己构建它)。
另外两个你可以自己搭建或者使用我做的轮子。

如果您从源代码构建,那么您可以通过在三台不同的机器上并行运行 triton、flash-attention 和 aphrodite 的 python setup.py bdist_wheel 来节省一些时间。或者您可以在同一台机器上逐一执行它们。

runhead pip install 'numpy<2' torch==2.4.0 --index-url 'https://download.pytorch.org/whl/cu124'# fix for "libstdc++.so.6: version `glibcxx_3.4.30' not found" error:runhead conda install -y -c conda-forge libstdcxx-ng=12runhead python -c 'import torch; print(torch.tensor(2).cuda() + 2, "torch ok")'

来自车轮的 triton 和闪光注意

runhead pip install 'https://github.com/qpwo/lambda-gh200-llama-405b-tutorial/releases/download/v0.1/triton-3.2.0+git755d4164-cp311-cp311-linux_aarch64.whl'runhead pip install 'https://github.com/qpwo/lambda-gh200-llama-405b-tutorial/releases/download/v0.1/aphrodite_flash_attn-2.6.1.post2-cp311-cp311-linux_aarch64.whl'

海卫一从源头

k=1 ssh_k # ssh into first machinepip install -u pip setuptools wheel ninja cmake setuptools_scmgit config --global feature.manyfiles true # faster clonesgit clone https://github.com/triton-lang/triton.git ~/shared/tritoncd ~/shared/triton/pythongit checkout 755d4164 # <-- optional, tested versions# note that ninja already parallelizes everything to the extent possible,# so no sense trying to change the cmake flags or anything.python setup.py bdist_wheelpip install --no-deps dist/*.whl # good idea to download this too for laterpython -c 'import triton; print("triton ok")'

来自源头的闪光注意力

k=2 ssh_k # go into second machinegit clone https://github.com/alpindale/flash-attention  ~/shared/flash-attentioncd ~/shared/flash-attentionpython setup.py bdist_wheelpip install --no-deps dist/*.whlpython -c 'import aphrodite_flash_attn; import aphrodite_flash_attn_2_cuda; print("flash attn ok")'

安装阿芙罗狄蒂

你可以使用我的轮子或自己建造。

轮子上的阿佛洛狄忒

runhead pip install 'https://github.com/qpwo/lambda-gh200-llama-405b-tutorial/releases/download/v0.1/aphrodite_engine-0.6.4.post1-cp311-cp311-linux_aarch64.whl'

阿佛洛狄忒的来源

k=3 ssh_k # building this on the third machinegit clone https://github.com/pygmalionai/aphrodite-engine.git ~/shared/aphrodite-enginecd ~/shared/aphrodite-enginepip install protobuf==3.20.2 ninja msgspec coloredlogs portalocker pytimeparse  -r requirements-common.txtpython setup.py bdist_wheelpip install --no-deps dist/*.whl

检查所有安装是否成功

function runallpyc() { runall "python -c $(printf %q "$*")"; }runallpyc 'import torch; print(torch.tensor(5).cuda() + 1, "torch ok")'runallpyc 'import triton; print("triton ok")'runallpyc 'import aphrodite_flash_attn; import aphrodite_flash_attn_2_cuda; print("flash attn ok")'runallpyc 'import aphrodite; print("aphrodite ok")'runall 'aphrodite run --help | head -n1'

下载权重

转到https://huggingface.co/meta-llama/llama-3.1-405b-instruct并确保您拥有正确的权限。批准通常需要大约一个小时。从https://huggingface.co/settings/tokens
获取令牌

pip install hf_transfer 'huggingface_hub[hf_transfer]'runall git config --global credential.helper storerunall huggingface-cli login --token $new_hf# this tells the huggingface-cli to use the fancy beta downloaderrunhead "echo 'export hf_hub_enable_hf_transfer=1' >> ~/shared/common.sh"runall 'echo $hf_hub_enable_hf_transfer'runall pkill -ife huggingface-cli # kill any stragglers# we can speed up the model download by having each server download partlocal_dir=/home/ubuntu/shared/hff/405b-instructk=1 run_k huggingface-cli download --max-workers=32 --revision="main" --include="model-000[0-4]?-of-00191.safetensors" --local-dir=$local_dir meta-llama/meta-llama-3.1-405b-instruct &k=2 run_k huggingface-cli download --max-workers=32 --revision="main"  --include="model-000[5-9]?-of-00191.safetensors" --local-dir=$local_dir meta-llama/meta-llama-3.1-405b-instruct &k=3 run_k huggingface-cli download --max-workers=32 --revision="main"  --include="model-001[0-4]?-of-00191.safetensors" --local-dir=$local_dir meta-llama/meta-llama-3.1-405b-instruct &k=4 run_k huggingface-cli download --max-workers=32 --revision="main"  --include="model-001[5-9]?-of-00191.safetensors" --local-dir=$local_dir meta-llama/meta-llama-3.1-405b-instruct &wait# download misc remaining filesk=1 run_k huggingface-cli download --max-workers=32 --revision="main" --exclude='*.pth' --local-dir=$local_dir meta-llama/meta-llama-3.1-405b-instruct

奔跑骆驼 405b

我们将通过启动 ray 让服务器相互了解。

runhead pip install -u "ray[data,train,tune,serve]"runall which ray# runall ray stoprunhead ray start --head --disable-usage-stats # note the ip and port ray provides# you can also get the private ip of a node with this command:# ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d/ -f1 | head -n 1runrest ray start --address=?.?.?.?:6379runhead ray status # should see 0.0/10.0 gpu (or however many you set up)

我们可以在一个终端选项卡中启动阿芙罗狄蒂:

# ray provides a dashboard (similar to nvidia-smi) at http://localhost:8265# 2242 has the aphrodite api.ssh -l 8265:localhost:8265 -l 2242:localhost:2242 ubuntu@$(head -n1 ~/ips.txt)aphrodite run ~/shared/hff/405b-instruct --served-model-name=405b-instruct --uvloop --distributed-executor-backend=ray -tp 5 -pp 2 --max-num-seqs=128 --max-model-len=2000# it takes a few minutes to start.# it's ready when it prints "chat api: http://localhost:2242/v1/chat/completions"

并在第二个终端中从本地计算机运行查询:

pip install openaipython -c 'import timefrom openai import openaiclient = openai(api_key="empty", base_url="http://localhost:2242/v1")started = time.time()num_tok = 0for part in client.completions.create(    model="405b-instruct",    prompt="live free or die. that is",    temperature=0.7,    n=1,    max_tokens=200,    stream=true,):    text = part.choices[0].text or ""    print(text, end="", flush=true)    num_tok += 1elapsed = time.time() - startedprint()print(f"{num_tok=} {elapsed=:.2} tokens_per_sec={num_tok / elapsed:.1f}")'
 THE LIFE FOR ME."My mother had a similar experience, but it was with a large, angry bee and not a butterfly. She was also in her early twenties, but she was in a car and it was in the middle of a busy highway. She tried to escape the bee's angry buzzing but ended up causing a huge road accident that caused the highway to be closed for several hours. Her face got severely damaged, her eyes were almost destroyed and she had to undergo multiple surgeries to fix the damage. Her face never looked the same after the incident. She was lucky to have survived such a traumatic experience.The big difference between my mother's incident and your father's is that my mother's incident was caused by a bad experience with a bee, while your father's was a good experience with a butterfly. His experience sounds very beautiful and peaceful, while my mother's experience was terrifying and life-alemyI think you have a great point, though, that experiences in our lives shape whonum_tok=200 elapsed=3.8e+01 tokens_per_sec=5.2

对于文本来说速度不错,但是对于代码来说有点慢。如果您连接 2 台 8xh100 服务器,那么每秒会接近 16 个令牌,但成本是原来的三倍。

进一步阅读

理论上,您可以使用 lambda labs api 编写实例创建和销毁脚本https://cloud.lambdalabs.com/api/v1/docs阿佛洛狄忒文档https://aphrodite.pygmalion.chat/vllm 文档(api 大部分相同)https://docs.vllm.ai/en/latest/

以上就是如何使用 ghs 运行 llama b bf的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1354990.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月13日 18:57:20
下一篇 2025年12月11日 18:22:12

相关推荐

  • Python Day-List 理解-练习

    列表理解 当您想要基于现有列表的值创建新列表时,列表理解提供了更短的语法。 (参考-https://www.w3schools.com/python/python_lists_comprehension.asp) 示例:1方法:1 fruits = [“apple”, “banana”, “cher…

    好文分享 2025年12月13日
    000
  • 处理 Python 事件循环关闭,无异常

    #! /usr/bin/env python3from asyncio import gather, get_event_loop, sleep, Eventfrom signal import SIGINT, SIGTERMdef shutdown_signaled(): print(‘Shutd…

    好文分享 2025年12月13日
    000
  • 了解 Python 中的 Lambda、Map 和 Filter

    Python 中 Lambda、Map 和 Filter 函数的巧妙运用 编写高效易读的 Python 代码至关重要。Lambda、map 和 filter 函数为数据处理和转换提供了简洁优雅的方案。本文将深入探讨这三个函数,并通过示例演示如何组合使用它们来高效解决问题。 Lambda 函数:匿名函…

    2025年12月13日
    000
  • linux如何执行python脚本

    Linux下执行Python脚本不仅依赖于系统默认解释器,还可以使用shebang、虚拟环境、并发处理、错误处理和日志记录,以提高效率、稳定性和易于维护性:指定绝对路径的解释器,避免版本冲突。使用shebang,赋予脚本执行权限,提升便利性。创建虚拟环境,安装特定库,保障依赖性。运用多进程或多线程,…

    2025年12月13日
    000
  • python脚本如何运行

    Python脚本运行涉及Python解释器逐行执行代码。除了命令行运行,还可以使用IDE,它提供了更多功能,或通过subprocess模块在程序中运行其他脚本。优化脚本性能的建议包括使用更高效的算法和数据结构,避免不必要的循环,使用cProfile进行性能分析,不断学习和总结。 Python脚本的运…

    2025年12月13日
    000
  • python脚本实例

    Python脚本实例涵盖广泛,从简单的文件处理到复杂的并行计算。一个处理文本文件频率统计的示例脚本说明了简洁高效的脚本编写方法,从输入处理、文本清洗到计数统计,涵盖了基本原理和技巧。进一步的用法包括扩展编码格式支持,处理大文件和并行处理。新手常见错误涉及编码和正则表达式使用。调试技巧包含中间变量打印…

    2025年12月13日
    000
  • python脚本教程

    Python脚本编写并不困难,只需掌握Python基础(变量、数据类型、条件、循环),了解Python脚本的简洁高效,即可入门。核心部分包括函数调用(如print()打印信息)和高级用法(如文件操作、循环、异常处理),通过实践和调试技巧(如使用print()打印变量、使用调试器)逐步提升脚本编写能力…

    2025年12月13日
    000
  • shell怎么调用python脚本

    在 shell 中优雅地调用 Python 脚本需要:使用 exec 命令替代 Python 脚本;使用进程替换在后台运行脚本并获取输出和错误;捕获脚本退出状态并判断执行结果;考虑参数传递和错误处理;根据需要添加日志记录和定时任务等扩展功能;使用 subprocess 模块进行性能优化(高级)。 S…

    2025年12月13日
    000
  • Python 日期列表函数

    python 列表操作及排序算法详解 本文深入探讨 Python 列表的常用操作,包括元素添加、排序、查找等,并详细讲解冒泡排序算法及其应用。 内容涵盖面试中常见的列表操作问题,例如查找第二大/小值等。 列表元素添加:append()、extend()、insert() insert():在指定位置…

    2025年12月13日
    000
  • 日期字符串函数

    Python 字符串函数详解及示例 本文将详细介绍几个常用的 Python 字符串函数:istitle()、replace()、rfind()、rindex() 和 split(),并通过示例代码演示它们的用法和区别。 1. istitle() 函数:检查标题大小写 istitle() 方法用于检查…

    2025年12月13日
    000
  • python脚本源码下载

    下载 Python 脚本时需考虑异常情况,如服务器宕机、网络中断和文件损坏。健壮的下载脚本应包含以下步骤:使用 requests 库的 stream=True 和 iter_content() 分块下载,降低内存占用。使用 response.raise_for_status() 处理 HTTP 错误…

    2025年12月13日
    000
  • python脚本怎么写

    如何写好 Python 脚本?理解代码实现想法的重要性,避免盲目操作。利用 Python 的简洁性,简化语法,如只需一行代码即可打印“Hello, world!”。使用正则表达式灵活提取文本信息,但掌握正则表达式至关重要。根据数据量选择合适的库,如 Pandas 库可高效处理大量数据。注重代码风格,…

    2025年12月13日
    000
  • java怎么调用python脚本

    Java调用Python有两种方法:使用ProcessBuilder直接执行脚本或使用Jython嵌入解释器。ProcessBuilder适合简单脚本和低兼容性需求,Jython则更适合复杂代码和紧密集成。注意错误处理、性能优化,以及不同方法的优缺点和局限性。 Java调用Python脚本:深度探索…

    2025年12月13日
    000
  • java怎么执行python脚本

    Java调用Python脚本可以通过以下几种方式实现:使用进程间通信机制,如Runtime.getRuntime().exec()(但存在效率和资源管理问题)使用Jython在JVM上运行Python代码(高效率但兼容性可能受限)使用消息队列实现异步通信(高并发场景下更适合) Java执行Pytho…

    2025年12月13日
    000
  • cmd运行python脚本

    直接敲命令行运行 Python 脚本,需要确保 Python 已安装并添加到环境变量中。命令本身包含引号处理空格、sys.argv 模块处理命令行参数等技巧。更高级可使用批处理文件或 shell 脚本自动化任务。熟练掌握这些技巧、错误处理和 IDE 调试,将提升脚本运行效率和代码质量。 直接敲命令行…

    2025年12月13日
    000
  • Python 中的枚举

    请我喝杯咖啡☕ enumerate() 可以创建一个 iterable,它有一个数字加 1 的 iterable,如下所示: *备注: 第一个参数是可迭代的(必需类型:可迭代)。第二个参数是 start(optional-default:0-type:int)。iterable 不能直接用索引访问,…

    好文分享 2025年12月13日
    000
  • pip如何更新到最新版本 更新pip版本的命令是

    pip更新方法:使用 pip install –upgrade pip 可简单更新 pip。通过了解 pip 更新机制和错误处理,实现更稳妥的更新。使用虚拟环境隔离项目依赖,避免版本冲突,更易管理。采用错误处理机制的代码示例,提供更新状态和问题排查信息。 pip更新:不止是pip ins…

    2025年12月13日
    000
  • 使用 ClientAI 和 Ollama 构建本地 AI 代码审查器 – 第 2 部分

    在第 1 部分中,我们为代码审查器构建了核心分析工具。现在我们将创建一个可以有效使用这些工具的人工智能助手。我们将逐步介绍每个组件,解释所有组件如何协同工作。 有关 clientai 的文档,请参阅此处;有关 github repo,请参阅此处。 系列索引 第 1 部分:简介、设置、工具创建第 2 …

    2025年12月13日
    000
  • 用于强大应用程序的强大 Python 数据验证技术

    在构建可靠的 Python 应用时,数据验证至关重要。本文将探讨五种强大的数据验证方法,它们能有效减少错误,提升代码质量。 1. Pydantic:数据建模与验证的利器 Pydantic 简洁高效,是数据建模和验证的理想选择。以下示例展示了其用法: from pydantic import Base…

    2025年12月13日
    000
  • N 的第 K 个因子 – O(sqrt n) 算法

    深入探讨o(√n)时间复杂度算法:leetcode因子查找问题 本文深入探讨LeetCode一道求解正整数第k个因子的问题,并介绍一种O(√n)时间复杂度的解法,优化了传统的O(n)方法。 问题描述 给定两个正整数n和k,求n的升序排列因子列表中的第k个因子。若n少于k个因子,则返回-1。 传统O(…

    2025年12月13日
    000

发表回复

登录后才能评论
关注微信