LeCun이 좋아하는 점: Apple M1/M2 칩에서 LLaMA를 실행하는 것! 130억 개의 매개변수 모델에는 4GB의 메모리만 필요합니다.
얼마 전 Meta가 오픈 소스 대형 언어 모델 LLaMA를 출시한 후 네티즌들은 임계값 없는 다운로드 링크를 공개했는데, 이는 "비참하게" 열려 있었습니다.
뉴스가 나오자마자 서클은 순식간에 활기를 띠었고 모두가 다운로드하고 테스트하기 시작했습니다.
그런데 최고급 그래픽 카드가 없는 친구들은 모델만 보고 한숨만 나옵니다.
그러나 큰 문제는 아닙니다. Georgi Gerganov는 최근 "llama.cpp"라는 프로젝트를 만들었습니다. LLaMA는 GPU 없이 실행될 수 있습니다.
프로젝트 주소: https://github.com/ggerganov/llama.cpp
예, 여기에는 Apple 칩이 장착된 Mac도 포함됩니다. 그리고 르쿤으로부터 포워딩 지원도 받았습니다.
M1/M2 Mac에서 LLaMA 실행
현재 Apple의 M1 및 M2 프로세서를 각각 기반으로 하는 상대적으로 포괄적인 두 가지 튜토리얼이 있습니다.
첫 번째 글: https://dev.l1x.be/posts/2023/03/12/using-llama-with-m1-mac/
두 번째 기사: https://til.simonwillison.net/llms/llama-7b-m2
더 이상 고민하지 말고 먼저 효과를 살펴보겠습니다.
예를 들어, 가장 작은 7B 모델에서는 "최초로 달에 착륙한 사람은 누구였나요?"라고 질문해 보세요.
매우 빠르게 결과는 몇 초 만에 나왔습니다.
-p '최초로 달에 발을 디딘 사람은'
최초로 달에 발을 디딘 사람은 38세의 우주 비행사 닐 A. 암스트롱이었습니다.
1969년 7월 20일, 아폴로 11호가 달에 착륙했습니다.
아폴로 11호는 최초의 유인 달 착륙 임무이자 우주 경쟁의 정점이었습니다. 1969년 7월, 닐 암스트롱(Neil Armstrong)과 에드윈 "버즈" 올드린(Edwin "Buzz" Aldrin)은 달에 착륙한 최초의 인간이 되었습니다.
아폴로 11호는 7월 16일 케네디 우주센터에서 발사되었습니다.
암스트롱의 나이, 중간 이름, 달 착륙 날짜에는 명백한 사실 오류가 없습니다. 이렇게 작은 모델에는 쉽지 않습니다.
다음 팁을 활용하면 실용적인 Python 코드를 생성할 수 있습니다.
-p 'def open_and_return_content(filename):'
def open_and_return_content(filename): """Opens file (returning the content) and performs basic sanity checks"""if os.path.isfile(filename): with open(filename) as f: content = f.read() return contentelse: print('WARNING: file "{}" does not exist'.format(filename), file=sys.stderr) return ''def get_file_info(filename, fullpath): """Get file information (i.e., permission, owner, group, size)"""
接下来,我们就来看看具体是如何实现的。
1단계: 모델 다운로드
가장 먼저 해야 할 일은 LLaMA 모델을 다운로드하는 것입니다.
공식 양식을 통해 Meta에 지원서를 제출하거나 네티즌이 공유한 링크에서 직접 받을 수 있습니다.
어쨌든 작업이 끝나면 다음과 같은 항목이 쌓여 있는 것을 볼 수 있습니다.
보시다시피, 다양한 모델이 서로 다른 폴더에 있습니다. 각 모델에는 모델에 대한 세부 정보가 포함된 params.json이 있습니다. 예:
2단계: 종속성 설치
首先,你需要安装Xcode来编译C++项目。
xcode-select --install
接下来,是构建C++项目的依赖项(pkgconfig和cmake)。
brew install pkgconfig cmake
在环境的配置上,假如你用的是Python 3.11,则可以创建一个虚拟环境:
/opt/homebrew/bin/python3.11 -m venv venv
然后激活venv。(如果是fish以外的shell,只要去掉.fish后缀即可)
. venv/bin/activate.fish
最后,安装Torch。
pip3 install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cpu
如果你对利用新的Metal性能着色器(MPS)后端进行GPU训练加速感兴趣,可以通过运行以下程序来进行验证。但这不是在M1上运行LLaMA的必要条件。
python Python 3.11.2 (main, Feb 16 2023, 02:55:59) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import torch; torch.backends.mps.is_available()True
第三步:编译LLaMA CPP
git clone git@github.com:ggerganov/llama.cpp.git
在安装完所有的依赖项后,你可以运行make:
make I llama.cpp build info: I UNAME_S:Darwin I UNAME_P:arm I UNAME_M:arm64 I CFLAGS: -I.-O3 -DNDEBUG -std=c11 -fPIC -pthread -DGGML_USE_ACCELERATE I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread I LDFLAGS: -framework Accelerate I CC: Apple clang version 14.0.0 (clang-1400.0.29.202)I CXX:Apple clang version 14.0.0 (clang-1400.0.29.202) cc-I.-O3 -DNDEBUG -std=c11 -fPIC -pthread -DGGML_USE_ACCELERATE -c ggml.c -o ggml.o c++ -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread -c utils.cpp -o utils.o c++ -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread main.cpp ggml.o utils.o -o main-framework Accelerate ./main -h usage: ./main [options] options: -h, --helpshow this help message and exit -s SEED, --seed SEEDRNG seed (default: -1) -t N, --threads N number of threads to use during computation (default: 4) -p PROMPT, --prompt PROMPT prompt to start generation with (default: random) -n N, --n_predict N number of tokens to predict (default: 128) --top_k N top-k sampling (default: 40) --top_p N top-p sampling (default: 0.9) --temp Ntemperature (default: 0.8) -b N, --batch_size Nbatch size for prompt processing (default: 8) -m FNAME, --model FNAME model path (default: models/llama-7B/ggml-model.bin) c++ -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread quantize.cpp ggml.o utils.o -o quantize-framework Accelerate
第四步:转换模型
假设你已经把模型放在llama.cpp repo中的models/下。
python convert-pth-to-ggml.py models/7B 1
那么,应该会看到像这样的输出:
{'dim': 4096, 'multiple_of': 256, 'n_heads': 32, 'n_layers': 32, 'norm_eps': 1e-06, 'vocab_size': 32000}n_parts =1Processing part0Processing variable: tok_embeddings.weight with shape:torch.Size([32000, 4096])and type:torch.float16 Processing variable: norm.weight with shape:torch.Size([4096])and type:torch.float16 Converting to float32 Processing variable: output.weight with shape:torch.Size([32000, 4096])and type:torch.float16 Processing variable: layers.0.attention.wq.weight with shape:torch.Size([4096, 4096])and type:torch.f loat16 Processing variable: layers.0.attention.wk.weight with shape:torch.Size([4096, 4096])and type:torch.f loat16 Processing variable: layers.0.attention.wv.weight with shape:torch.Size([4096, 4096])and type:torch.f loat16 Processing variable: layers.0.attention.wo.weight with shape:torch.Size([4096, 4096])and type:torch.f loat16 Processing variable: layers.0.feed_forward.w1.weight with shape:torch.Size([11008, 4096])and type:tor ch.float16 Processing variable: layers.0.feed_forward.w2.weight with shape:torch.Size([4096, 11008])and type:tor ch.float16 Processing variable: layers.0.feed_forward.w3.weight with shape:torch.Size([11008, 4096])and type:tor ch.float16 Processing variable: layers.0.attention_norm.weight with shape:torch.Size([4096])and type:torch.float 16... Done. Output file: models/7B/ggml-model-f16.bin, (part0 )
下一步将是进行量化处理:
./quantize ./models/7B/ggml-model-f16.bin ./models/7B/ggml-model-q4_0.bin 2
输出如下:
llama_model_quantize: loading model from './models/7B/ggml-model-f16.bin'llama_model_quantize: n_vocab = 32000llama_model_quantize: n_ctx = 512llama_model_quantize: n_embd= 4096llama_model_quantize: n_mult= 256llama_model_quantize: n_head= 32llama_model_quantize: n_layer = 32llama_model_quantize: f16 = 1... layers.31.attention_norm.weight - [ 4096, 1], type =f32 size =0.016 MB layers.31.ffn_norm.weight - [ 4096, 1], type =f32 size =0.016 MB llama_model_quantize: model size= 25705.02 MB llama_model_quantize: quant size=4017.27 MB llama_model_quantize: hist: 0.000 0.022 0.019 0.033 0.053 0.078 0.104 0.125 0.134 0.125 0.104 0.078 0.053 0.033 0.019 0.022 main: quantize time = 29389.45 ms main:total time = 29389.45 ms
第五步:运行模型
./main -m ./models/7B/ggml-model-q4_0.bin -t 8 -n 128 -p 'The first president of the USA was '
main: seed = 1678615879llama_model_load: loading model from './models/7B/ggml-model-q4_0.bin' - please wait ... llama_model_load: n_vocab = 32000llama_model_load: n_ctx = 512llama_model_load: n_embd= 4096llama_model_load: n_mult= 256llama_model_load: n_head= 32llama_model_load: n_layer = 32llama_model_load: n_rot = 128llama_model_load: f16 = 2llama_model_load: n_ff= 11008llama_model_load: n_parts = 1llama_model_load: ggml ctx size = 4529.34 MB llama_model_load: memory_size = 512.00 MB, n_mem = 16384llama_model_load: loading model part 1/1 from './models/7B/ggml-model-q4_0.bin'llama_model_load: .................................... donellama_model_load: model size =4017.27 MB / num tensors = 291 main: prompt: 'The first president of the USA was 'main: number of tokens in prompt = 9 1 -> ''1576 -> 'The' 937 -> ' first'6673 -> ' president' 310 -> ' of' 278 -> ' the'8278 -> ' USA' 471 -> ' was' 29871 -> ' ' sampling parameters: temp = 0.800000, top_k = 40, top_p = 0.950000 The first president of the USA was 57 years old when he assumed office (George Washington). Nowadays, the US electorate expects the new president to be more young at heart. President Donald Trump was 70 years old when he was inaugurated. In contrast to his predecessors, he is physically fit, healthy and active. And his fitness has been a prominent theme of his presidency. During the presidential campaign, he famously said he would be the “most active president ever” — a statement Trump has not yet achieved, but one that fits his approach to the office. His tweets demonstrate his physical activity. main: mem per token = 14434244 bytes main: load time =1311.74 ms main: sample time = 278.96 ms main:predict time =7375.89 ms / 54.23 ms per token main:total time =9216.61 ms
资源使用情况
第二位博主表示,在运行时,13B模型使用了大约4GB的内存,以及748%的CPU。(设定的就是让模型使用8个CPU核心)
没有指令微调
GPT-3和ChatGPT效果如此之好的关键原因之一是,它们都经过了指令微调,
这种额外的训练使它们有能力对人类的指令做出有效的反应。比如「总结一下这个」或「写一首关于水獭的诗」或「从这篇文章中提取要点」。
撰写教程的博主表示,据他观察,LLaMA并没有这样的能力。
也就是说,给LLaMA的提示需要采用经典的形式:「一些将由......完成的文本」。这也让提示工程变得更加困难。
举个例子,博主至今都还没有想出一个正确的提示,从而让LLaMA实现文本的总结。
위 내용은 LeCun이 좋아하는 점: Apple M1/M2 칩에서 LLaMA를 실행하는 것! 130억 개의 매개변수 모델에는 4GB의 메모리만 필요합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

일련의 질문 : 신속한 엔지니어링 혁명 각 질문이 이전의 질문을 기반으로하는 AI와의 대화를 상상해보십시오. 이것은 신속한 엔지니어링에서 일련의 질문 (COQ)의 힘입니다.

Mistral Nemo : 강력한 오픈 소스 다국어 LLM Mistral AI와 Nvidia의 협력 노력 인 Mistral Nemo는 최첨단 자연 자연 언어 처리를 제공하는 최첨단 오픈 소스 대형 언어 모델 (LLM)입니다. 이 12 억 파

정확한 수치 데이터를 위해 Microsoft Excel의 라운드 기능을 마스터합니다 숫자는 스프레드 시트의 기본이지만 정확성과 가독성을 달성하려면 종종 원시 데이터 이상의 것이 필요합니다. Microsoft Excel의 라운드 기능은 TRA를위한 강력한 도구입니다.

AI 인텔리전스 향상 : llamaindex를 가진 반사 AI 에이전트에 대한 깊은 다이빙 문제를 해결할뿐만 아니라 개선을위한 자체 사고 과정을 반영하는 AI를 상상해보십시오. 이것은 반사 AI 요원의 영역 이며이 기사는 탐구합니다.

향상된 컨텐츠 검색을 위해 Langchain 및 벡터 임베딩을 활용합니다 이전 기사는 쿼리 관련 컨텐츠 추출을위한 데이터로드 및 분할 기술을 다루었습니다. 이 기사는 벡터 임베딩을 사용하여 고급 데이터 검색을 탐구합니다.

데이터 과학 경력 : 2024 년 최고의 회사 및 성공을위한 팁 최근 데이터 과학 졸업생 및 최종 1 년간의 공학 학생들은 다국적 기업 (MNC)을 목표로합니다. 많은 옵션이 있습니다. 이 안내서는 데이터를 고용하는 주요 회사를 강조합니다

생성 AI를 통한 고객 경험 향상 : 전략적 접근 고객 만족도가 가장 중요하며 비즈니스는 점점 탁월한 경험을 제공 할 필요성을 인식하고 있습니다. 고객의 70% 이상이 개인화 된 서비스를 원합니다

AI 주간 다이제스트 : 획기적인 혁신 및 윤리적 고려 사항 AV 바이트에 다시 오신 것을 환영합니다. 이번 주 하이라이트는 텍스트-이미지 생성, Model Efficie의 놀라운 진행 상황을 보여줍니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기
