# llama2.c for Dummies (초보자를 위한 llama2.c 가이드)

**URL:** https://discuss.pytorch.kr/t/llama2-c-for-dummies-llama2-c/2200
**Category:** 읽을거리&정보공유
**Tags:** llama2, llama2-c
**Created:** [7월 31, 2023, 8:42오전 UTC](https://discuss.pytorch.kr/t/llama2-c-for-dummies-llama2-c/2200 "2023-07-31T08:42:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![9bow](https://discuss.pytorch.kr/user_avatar/discuss.pytorch.kr/9bow/32/16301_2.png) [@9bow](https://discuss.pytorch.kr/u/9bow)
#### Post date: [7월 31, 2023, 8:42오전 UTC](https://discuss.pytorch.kr/t/llama2-c-for-dummies-llama2-c/2200/1 "2023-07-31T08:42:09Z")

</div>

- _이 글은 GPT 모델로 자동 요약한 설명으로, 잘못된 내용이 있을 수 있으니 원문을 참고해주세요! 😄_
- _읽으시면서 어색하거나 잘못된 내용을 발견하시면 덧글로 알려주시기를 부탁드립니다! 🙇‍♂️_

> **[GitHub - RahulSChand/llama2.c-for-dummies: Step by step explanation/tutorial of llama2.c](https://github.com/RahulSChand/llama2.c-for-dummies)**
>
> Step by step explanation/tutorial of llama2.c

* * *

## 소개

[RahulSChand/llama2.c-for-dummies GitHub 저장소](https://github.com/RahulSChand/llama2.c-for-dummies)는 Llama2.c에 대한 자세한 설명과 튜토리얼을 제공합니다. Llama2.c는 인공지능(AI) 언어 모델 LLM(Large Language Model)을 C 언어로 구현한 것입니다. 이 가이드는 LLM의 작동 방식과 이를 C 언어로 어떻게 코딩하는지에 대해 자세히 설명하고 있습니다.

## 요약

이 저장소는 llama2.c 코드에 대한 이해를 돕기 위해 만들어졌습니다. 이 코드는 인공지능(AI) 학습에서 중요한 역할을 하는 forward propagation에 대한 이해를 돕는 것이 목적입니다. 이 코드는 주로 구조체(Structs)와 메인 함수에 대한 설명으로 구성되어 있습니다.

 ![image](https://discuss.pytorch.kr/uploads/default/original/2X/e/eb56094e433e17870cae67aeec302f7565bfd89e.png)

### 셀프-어텐션 계산 (Doing self-attention)

이 섹션에서는 자기 주의 계산에 대한 공식을 설명하고 있습니다. 주요 변수들은 Q, K, V이며, 이들은 각각 쿼리, 키, 값에 해당합니다. 이들은 모두 현재 생성된 텍스트의 길이인 'pos'에 따라 달라집니다. 코드에서는 이들을 's-\>q', 's-\>k'와 같이 표현하며, 이들의 형태는 `(dim, n_heads, head_dim)`입니다. 이 섹션에서는 이러한 변수들을 어떻게 계산하는지에 대한 자세한 설명이 제공됩니다.

### 피드 포워드 & 분류기 (Feed Forward & Classifier)

이 섹션에서는 주의 모듈을 완성하기 위해 필요한 계산들을 설명합니다. 이들은 입력과 주의의 출력을 더하는 'accum' 함수와 정규화를 포함합니다. 또한, FFN 출력을 계산하는 방법도 설명하고 있습니다.

### 최종 분류기 (Final Classifier)

모든 레이어에 대한 모듈을 실행한 후에는 `(dim,)` 형태의 임베딩을 얻게 됩니다. 이 임베딩을 `(vocab,)` 형태의 벡터로 변환해야 합니다. 이 벡터의 각 항목은 다음 토큰이 해당 단어일 확률을 나타냅니다. 이 섹션에서는 이러한 변환을 어떻게 수행하는지에 대해 설명하고 있습니다.

## 더 읽어보기

LLaMA2 소개 글입니다.

> [@Meta, 상업적 사용이 가능한 오픈소스 언어 모델 LLaMA 2 공개 (7B, 13B, 70B / 4k context)](https://discuss.pytorch.kr/t/meta-llama-2-7b-13b-70b-4k-context/2095):
>
> 소개 [image] Meta:meta\_logo:가 기존 LLaMA보다 40% 가량 더 많은 데이터로 학습한 LLaMA2를 공개하였습니다 tada 7B, 13B, 70B의 모델들을 공개하였으며, 모델 코드와 가중치 모두를 공개하였습니다. 상업적 사용이 가능하며, [모델 요청 양식을 제출](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)하면 다운로드 가능한 인증 URL을 받으실 수 있습니다. (요청 양식에 뭔가 License Agreement가 잔뜩 길어졌습니다 rofl ) [LLaMA-2 Overview] [LLaMA-2 Benchmark] [LLaMA-2 RLHF] 바로가기 프로젝트 홈페이지 [https://ai.meta.com/llama/](https://ai.meta.com/llama/)GitHub 저장소 [https://github.com/facebookresearch/llama](https://github.com/facebookresearch/llama)모델 다운로드 요청 양식 [https://ai.meta.com/resources/models-and-libraries/llama-downloads/](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)논문 초록(Abstract) 이…

LLaMA2.c 소개 글입니다.

> [@Llama2.c: 순수 C로 작성된 Llama 2 추론 코드 (Llama2.c: Inference Llama 2 in one file of pure C)](https://discuss.pytorch.kr/t/llama2-c-c-llama-2-llama2-c-inference-llama-2-in-one-file-of-pure-c/2141):
>
> 이 글은 GPT-4를 사용하여 자동 생성한 설명으로, 잘못된 내용이 있을 수 있습니다. smile잘못된 내용을 발견하시면 덧글로 알려주시기를 부탁드립니다! bowing_man소개 Llama2.c는 Andrej Karpathy가 개발한 순수 C로 작성된 Inference Llama 2입니다. 이 프로젝트는 기계 학습 모델의 추론을 위한 경량화된 라이브러리로, C 언어로 작성되어 있어 다양한 플랫폼에서 사용할 수 있습니다. 이 라이브러리는 특히 작은 모델들에 대해 CPU에서 빠르게 작동하도록 설계되었습니다. 요약 이 라이브러리는 기계 학습 모델의 추론을 위한 경량화된 라이브러리로, C 언어로 작성되어 있어 다양한 플랫폼에서 사용할 수 있습니다. 이 라이브러리는 특히 작은 모델들에 대해 CPU에서 빠르게 작동하도록 설계되었습니다. 이 라이브러리는 특히 작은 모델들에 대해 CPU에서 빠르게 작동하도록 설계되었습니다. 이 프로젝트는 다양한 …

**[Understanding Forward Propagation for Deep Learning](https://towardsdatascience.com/forward-propagation-in-neural-networks-simplified-math-and-code-version-bbcfef6f9250)**: 이 블로그 글은 딥러닝을 위한 forward propagation에 대한 이해를 돕습니다.

> **[Neural Networks Backpropagation Made Easy | Towards Data Science](https://towardsdatascience.com/neural-networks-backpropagation-by-dr-lihi-gur-arie-27be67d8fdce/)**
>
> A friendly guide to the mathematical intuition behind vanilla Neural Networks. Figure 1. Backpropagation in a Neural Network | Image by Author Introduction Understanding the mathematical operations behind Neural Networks (NNs) is important for a data...

**[Neural Networks and Deep Learning](http://neuralnetworksanddeeplearning.com/):** 이 온라인 책은 신경망과 딥러닝에 대한 깊은 이해를 제공합니다.

> **[Neural networks and deep learning](http://neuralnetworksanddeeplearning.com/)**

**[Deep Learning Book by Goodfellow, Bengio, and Courville](http://www.deeplearningbook.org/)**: 이 책은 딥러닝에 대한 깊이 있는 이해를 제공하며, forward propagation에 대한 세부적인 설명을 포함하고 있습니다.

> **[Deep Learning](https://www.deeplearningbook.org/)**

**[Stanford's CS231n: Convolutional Neural Networks for Visual Recognition](http://cs231n.github.io/)**: 이 강의 자료는 컨볼루션 신경망에 대한 이해를 돕고, forward propagation에 대한 설명을 포함하고 있습니다.

> **[CS231n Deep Learning for Computer Vision](https://cs231n.github.io/)**
>
> Course materials and notes for Stanford class CS231n: Deep Learning for Computer Vision.

**[Backpropagation Step by Step](https://hmkcode.github.io/ai/backpropagation-step-by-step/)**: 이 블로그 글은 역전파에 대한 이해를 돕습니다. forward propagation에 이어서 이해해야 하는 중요한 개념입니다.

> **[Backpropagation Step by Step](https://hmkcode.com/ai/backpropagation-step-by-step/)**
>
> Backpropagation is a technique used for training neural network. There are many resources explaining the technique, but this post will explain backpropagation with concrete example in a very detailed colorful steps.

**[Language Models are Few-Shot Learners](https://arxiv.org/abs/2005.14165)**: LLM에 대한 기본적인 이해를 돕는 논문입니다.

> **[Language Models are Few-Shot Learners](https://arxiv.org/abs/2005.14165)**
>
> Recent work has demonstrated substantial gains on many NLP tasks and benchmarks by pre-training on a large corpus of text followed by fine-tuning on a specific task. While typically task-agnostic in architecture, this method still requires...

## 원문

> **[GitHub - RahulSChand/llama2.c-for-dummies: Step by step explanation/tutorial of llama2.c](https://github.com/RahulSChand/llama2.c-for-dummies)**
>
> Step by step explanation/tutorial of llama2.c
