{
    "componentChunkName": "component---src-templates-post-tsx",
    "path": "/moe/",
    "result": {"data":{"logo":null,"markdownRemark":{"html":"<h1>What it MoE? (Mixture of Experts)</h1>\n<p>현존 최강 LLM인 GPT-4에서 “MoE (Mixture of Experts)” 방식을 채택하여 사용하고 있다고 알려졌는데요, 최근 AI계의 뜨거운 감자 Mistral AI에서 <a href=\"https://huggingface.co/mistralai/Mistral-7B-v0.1\">Mistral-7B</a>라는 좋은 성능의 모델을 오픈소스로 공개한지 몇 달이 채 되지 않았는데 몇일 전, Mixtral이라는 46.7B 모델을 오픈소스로 공개했습니다!</p>\n<img src=\"https://github.com/sooftware/sooftware.io/assets/42150335/40a24753-386e-4271-bf4b-eb7ab90e8dbe\" height=\"140\">\n<p>모델 사이즈도 사이즈지만, Mixtral이 “MoE” 방식을 채택해서 사용했으며, LLaMA-2 70B를 상회하는 성능을 보여서 더욱 주목을 받고 있습니다. (Inference 속도는 6배나 빠르다고 합니다 🫢)</p>\n<img src=\"https://github.com/sooftware/sooftware.io/assets/42150335/cafd232f-c846-4502-b185-3db1ad06d21a\" height=\"270\">\n<p>Mixtral은 총 46.7B개의 파라미터 사이즈를 가지고 있찌만, 실제 인퍼런스할때는 12.9B의 추론 속도를 보여준다고 하는데요, 이게 어떻게 가능한 걸까요? 🤔</p>\n<p>이를 이해하기 위해서는 “MoE” 개념을 이해해야 합니다!</p>\n<h2>MoE (Mixture of Experts)</h2>\n<p>모델 파라미터 수가 많을수록, 모델 성능이 올라간다는 것은 이미 여러 연구를 통해 Scaling-Law가 입증되었습니다. 그래서 모델의 성능을 파악할때 파라미터 수는 가장 중요한 요소중 하나입니다. 하지만 모두가 OpenAI, Google, Meta 같은 빅테크 기업들처럼 컴퓨팅 자원을 자유롭게 사용할수는 없기에, 현실적으로 제한된 컴퓨팅 자원으로 모델 학습/서빙을 해야합니다.</p>\n<p>모델 사이즈가 커질수록 학습/서빙 비용은 늘어날 수 밖에 없는데, MoE는 학습/서빙 비용은 유지하면서도 모델 사이즈를 키울 수 있는 방법입니다!</p>\n<p>그럼 이제 본격적으로 MoE에 대해 살펴보겠습니다.</p>\n<ul>\n<li>\n<p><strong>Sparse MoE Layers</strong> : 기존 트랜스포머의 feed-forward network (FFN) 레이어를 N개의 <code class=\"language-text\">expert</code>로 나눠서 사용하는 개념입니다. 이 <code class=\"language-text\">expert</code>는 FFN이지만, 특정 <strong>토큰</strong>들을 담당한다고 생각하면 됩니다.</p>\n</li>\n<li>\n<p><strong>Gate Network (Router)</strong> : 각 토큰이 어떤 <code class=\"language-text\">expert</code>에 소속되는지를 결정하는 network.</p>\n</li>\n</ul>\n<img src=\"https://github.com/sooftware/sooftware.io/assets/42150335/72ea18a1-d0b9-4d06-ace7-78c013658136\" height=\"350\">\n<p><a href=\"https://arxiv.org/abs/2101.03961\">Switch Transformer</a>에 아주 좋은 예씨 Figure가 있어서 가져왔습니다. 위 그림처럼 Transformer Block은 Attention -> Add + Norm -> FFN -> Add + Norm과 같은 형태로 이루어져 있습니다. (순서는 아키텍처마다 다를 수 있습니다만 여기서는 넘어가겠습니다.) 여기서 MoE는 <strong>FFN</strong>에 해당하는 layer를 기존과 다르게 사용하는데요, 그림에서처럼 “More”라는 토큰 하나가 들어왔을 때, 이 토큰을 Gate Network (Router)를 거쳐서 N번째 <code class=\"language-text\">expert</code>에 할당되면, 해당 토큰은 다른 <code class=\"language-text\">experts</code>은 제외한 할당된 <code class=\"language-text\">expert</code>에 해당하는 FFN을 통과하게 됩니다. (밑에서 살펴보겠지만, 위 예시에서는 1개의 <code class=\"language-text\">expert</code>만을 할당받았지만, 실제로는 2개 이상의 <code class=\"language-text\">expert</code>도 보낼 수 있습니다. 😎)</p>\n<h3>Sparsity</h3>\n<img src=\"https://github.com/sooftware/sooftware.io/assets/42150335/d207e623-2e89-4791-a7b3-55d6da7c2bfa\" height=\"140\">\n<p>여기서 <strong>Sparsity</strong>에 대해 보고 넘어가겠습니다. 일반적인 트랜스포머 모델은 dense한 모델입니다. (모든 입력에 대해 모든 입력이 사용되는 모델) 반면에 Sparsity한 모델이란, 모델 파라미터의 일부만 사용할 수 있는 모델을 의미합니다. 즉, 이 MoE 아키텍처는 Sparsity하다고 할 수 있겠죠!</p>\n<h3>1개가 아닌 K개의 Expert에게 보내려면 어떻게 해야할까?</h3>\n<p>위에서 <code class=\"language-text\">Expert</code>를 2개 이상에 보낼수도 있다고 했습니다. Mixtral도 1개가 아닌 2개의 <code class=\"language-text\">Expert</code>에 보내는 방식으로 학습되었는데요, 어떻게 동작하는지 살펴보겠습니다.</p>\n<img src=\"https://github.com/sooftware/sooftware.io/assets/42150335/e6c0e658-f46f-4b40-859c-2c9c13ca731a\" height=\"100\">\n<p>총 8개의 <code class=\"language-text\">Expert</code>가 있고, 여기서 1개의 <code class=\"language-text\">Expert</code>로 보내는 문제를 먼저 보겠습니다. 굉장히 간단한 <strong>Classification</strong> 문제죠. PyTorch 코드로 구현한다면 아래와 같겠네요.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> torch<span class=\"token punctuation\">.</span>nn <span class=\"token keyword\">as</span> nn\n\n<span class=\"token comment\"># inputs는 dim 차원을 가진 tensor</span>\ndim<span class=\"token punctuation\">,</span> num_experts <span class=\"token operator\">=</span> <span class=\"token number\">512</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span>\ngate <span class=\"token operator\">=</span> nn<span class=\"token punctuation\">.</span>Linear<span class=\"token punctuation\">(</span>dim<span class=\"token punctuation\">,</span> num_experts<span class=\"token punctuation\">)</span>\nnth_expert <span class=\"token operator\">=</span> F<span class=\"token punctuation\">.</span>softmax<span class=\"token punctuation\">(</span>gate<span class=\"token punctuation\">(</span>inputs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> dim<span class=\"token operator\">=</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>argmax<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>이렇게 위와 같이 Linear layer + Softmax 조합으로 간단하게 <code class=\"language-text\">Expert</code>를 특정할 수 있고, 해당 토큰은 특정된 <code class=\"language-text\">Expert</code>로 포워딩해주면 됩니다.</p>\n<p>그렇다면, 만약에 1개 이상의 K개의 <code class=\"language-text\">Expert</code>에게 gating을 해주고 싶다면 어떻게 해야할까요? 🤔</p>\n<p>여러 방법이 있겠지만, Mixtral에서 사용한 Top-k Gating 방식을 소개드리겠습니다. gate network의 linear layer를 H(x)라고 하고, K개의 <code class=\"language-text\">Expert</code>에게 보내고 싶다면, 아래와 같은 수식으로 표현할 수 있습니다.</p>\n<img height=\"70\" alt=\"image\" src=\"https://github.com/sooftware/sooftware.io/assets/42150335/68702730-e153-4a7d-b39f-5eb7c6606f01\">\n<p>(이해를 위해 K=2를 예시로 들겠습니다.) Linear layer의 결과로 나온 logits에 top 2개의 logits을 뽑고 이 2개의 logits에 대해서 Softmax 함수를 적용합니다. 그럼 이 2개의 expert에 대한 weight 값이 나오게 됩니다!</p>\n<p>A라는 Expert에게 0.7, B라는 Expert에게 0.3과 같은 식으로 말이죠. 이렇게 나온 weight를 A와 B Expert를 거쳐서 나온 결과값에 곱해서 사용하게 됩니다.</p>\n<p>아래는 실제 Mixtral에 사용된 MoE Layer의 구현 코드입니다. 해당 코드에 제가 위에 설명한 내용들에 대해 주석으로 달아놨으니 참고하면서 하나하나 이해해보시는걸 추천드립니다!</p>\n<p>(참고) MoE 구현체는 <a href=\"https://github.com/mistralai/mistral-src/blob/main/mistral/moe.py\">이곳</a>에서 확인 가능합니다. 그리 길지 않아서 코드를 바로 가져왔습니다.</p>\n<h3>MoE Implementation (by Mistral)</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> dataclasses\n<span class=\"token keyword\">from</span> typing <span class=\"token keyword\">import</span> List\n\n<span class=\"token keyword\">import</span> torch\n<span class=\"token keyword\">import</span> torch<span class=\"token punctuation\">.</span>nn<span class=\"token punctuation\">.</span>functional <span class=\"token keyword\">as</span> F\n<span class=\"token keyword\">from</span> simple_parsing<span class=\"token punctuation\">.</span>helpers <span class=\"token keyword\">import</span> Serializable\n<span class=\"token keyword\">from</span> torch <span class=\"token keyword\">import</span> nn\n\n\n<span class=\"token decorator annotation punctuation\">@dataclasses<span class=\"token punctuation\">.</span>dataclass</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MoeArgs</span><span class=\"token punctuation\">(</span>Serializable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    num_experts<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span>\n    num_experts_per_tok<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span>\n\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MoeLayer</span><span class=\"token punctuation\">(</span>nn<span class=\"token punctuation\">.</span>Module<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> experts<span class=\"token punctuation\">:</span> List<span class=\"token punctuation\">[</span>nn<span class=\"token punctuation\">.</span>Module<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> gate<span class=\"token punctuation\">:</span> nn<span class=\"token punctuation\">.</span>Module<span class=\"token punctuation\">,</span> moe_args<span class=\"token punctuation\">:</span> MoeArgs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token builtin\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>__init__<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">assert</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>experts<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token number\">0</span>\n        self<span class=\"token punctuation\">.</span>experts <span class=\"token operator\">=</span> nn<span class=\"token punctuation\">.</span>ModuleList<span class=\"token punctuation\">(</span>experts<span class=\"token punctuation\">)</span>\n        self<span class=\"token punctuation\">.</span>gate <span class=\"token operator\">=</span> gate\n        self<span class=\"token punctuation\">.</span>args <span class=\"token operator\">=</span> moe_args\n\n    <span class=\"token keyword\">def</span> <span class=\"token function\">forward</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> inputs<span class=\"token punctuation\">:</span> torch<span class=\"token punctuation\">.</span>Tensor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token comment\"># Step 1 : Expert로 보내기 위한 gate linear layer 통과</span>\n        gate_logits <span class=\"token operator\">=</span> self<span class=\"token punctuation\">.</span>gate<span class=\"token punctuation\">(</span>inputs<span class=\"token punctuation\">)</span>\n        <span class=\"token comment\"># Step 2 : gate logits에 대해 Top-K개 Expert 뽑기</span>\n        weights<span class=\"token punctuation\">,</span> selected_experts <span class=\"token operator\">=</span> torch<span class=\"token punctuation\">.</span>topk<span class=\"token punctuation\">(</span>gate_logits<span class=\"token punctuation\">,</span> self<span class=\"token punctuation\">.</span>args<span class=\"token punctuation\">.</span>num_experts_per_tok<span class=\"token punctuation\">)</span>\n        <span class=\"token comment\"># Step 3 : Top-K개의 experts에 대한 weights 구하기 (by softmax)</span>\n        weights <span class=\"token operator\">=</span> F<span class=\"token punctuation\">.</span>softmax<span class=\"token punctuation\">(</span>weights<span class=\"token punctuation\">,</span> dim<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> dtype<span class=\"token operator\">=</span>torch<span class=\"token punctuation\">.</span><span class=\"token builtin\">float</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>to<span class=\"token punctuation\">(</span>inputs<span class=\"token punctuation\">.</span>dtype<span class=\"token punctuation\">)</span>\n        results <span class=\"token operator\">=</span> torch<span class=\"token punctuation\">.</span>zeros_like<span class=\"token punctuation\">(</span>inputs<span class=\"token punctuation\">)</span>\n\n        <span class=\"token comment\"># N개의 experts 돌면서 순회</span>\n        <span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> expert <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">.</span>experts<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n            <span class=\"token comment\"># Step 4 : i_th expert에 해당하는 tokens 뽑기</span>\n            batch_idx<span class=\"token punctuation\">,</span> nth_expert <span class=\"token operator\">=</span> torch<span class=\"token punctuation\">.</span>where<span class=\"token punctuation\">(</span>selected_experts <span class=\"token operator\">==</span> i<span class=\"token punctuation\">)</span>\n            <span class=\"token comment\"># Step 5 : i_th expert에 해당하는 token들 i_th expert에 통과</span>\n            <span class=\"token comment\"># Step 6 : 통과된 결과값에 expert weight 반영</span>\n            results<span class=\"token punctuation\">[</span>batch_idx<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> weights<span class=\"token punctuation\">[</span>batch_idx<span class=\"token punctuation\">,</span> nth_expert<span class=\"token punctuation\">,</span> <span class=\"token boolean\">None</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> expert<span class=\"token punctuation\">(</span>\n                inputs<span class=\"token punctuation\">[</span>batch_idx<span class=\"token punctuation\">]</span>\n            <span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">return</span> results</code></pre></div>\n<p>게이트가 여러 <code class=\"language-text\">Expert</code>에게 라우팅하는 방법을 학습하게 하기 위해서 이렇게 2개 이상의 <code class=\"language-text\">Expert</code>에게 보내도록 학습을 시켰다고 합니다.</p>\n<p>최근에 나온 여러 아키텍처들이 이 MoE 방식에 기반하여 만들어지고 있습니다! 그런만큼 MoE에 대한 이해가 중요한데, 이 포스팅이 도움이 됐으면 좋겠습니다!</p>\n<h2>Reference</h2>\n<ul>\n<li><a href=\"https://mistral.ai/news/mixtral-of-experts/\">https://mistral.ai/news/mixtral-of-experts/</a></li>\n<li><a href=\"https://huggingface.co/blog/moe\">https://huggingface.co/blog/moe</a></li>\n<li><a href=\"https://github.com/mistralai/mistral-src\">https://github.com/mistralai/mistral-src</a></li>\n</ul>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"h1","properties":{},"children":[{"type":"text","value":"What it MoE? (Mixture of Experts)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"현존 최강 LLM인 GPT-4에서 “MoE (Mixture of Experts)” 방식을 채택하여 사용하고 있다고 알려졌는데요, 최근 AI계의 뜨거운 감자 Mistral AI에서 "},{"type":"element","tagName":"a","properties":{"href":"https://huggingface.co/mistralai/Mistral-7B-v0.1"},"children":[{"type":"text","value":"Mistral-7B"}]},{"type":"text","value":"라는 좋은 성능의 모델을 오픈소스로 공개한지 몇 달이 채 되지 않았는데 몇일 전, Mixtral이라는 46.7B 모델을 오픈소스로 공개했습니다!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"img","properties":{"src":"https://github.com/sooftware/sooftware.io/assets/42150335/40a24753-386e-4271-bf4b-eb7ab90e8dbe","height":140},"children":[]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"모델 사이즈도 사이즈지만, Mixtral이 “MoE” 방식을 채택해서 사용했으며, LLaMA-2 70B를 상회하는 성능을 보여서 더욱 주목을 받고 있습니다. (Inference 속도는 6배나 빠르다고 합니다 🫢)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"img","properties":{"src":"https://github.com/sooftware/sooftware.io/assets/42150335/cafd232f-c846-4502-b185-3db1ad06d21a","height":270},"children":[]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mixtral은 총 46.7B개의 파라미터 사이즈를 가지고 있찌만, 실제 인퍼런스할때는 12.9B의 추론 속도를 보여준다고 하는데요, 이게 어떻게 가능한 걸까요? 🤔"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"이를 이해하기 위해서는 “MoE” 개념을 이해해야 합니다!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h2","properties":{},"children":[{"type":"text","value":"MoE (Mixture of Experts)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"모델 파라미터 수가 많을수록, 모델 성능이 올라간다는 것은 이미 여러 연구를 통해 Scaling-Law가 입증되었습니다. 그래서 모델의 성능을 파악할때 파라미터 수는 가장 중요한 요소중 하나입니다. 하지만 모두가 OpenAI, Google, Meta 같은 빅테크 기업들처럼 컴퓨팅 자원을 자유롭게 사용할수는 없기에, 현실적으로 제한된 컴퓨팅 자원으로 모델 학습/서빙을 해야합니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"모델 사이즈가 커질수록 학습/서빙 비용은 늘어날 수 밖에 없는데, MoE는 학습/서빙 비용은 유지하면서도 모델 사이즈를 키울 수 있는 방법입니다!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"그럼 이제 본격적으로 MoE에 대해 살펴보겠습니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Sparse MoE Layers"}]},{"type":"text","value":" : 기존 트랜스포머의 feed-forward network (FFN) 레이어를 N개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"로 나눠서 사용하는 개념입니다. 이 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"는 FFN이지만, 특정 "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"토큰"}]},{"type":"text","value":"들을 담당한다고 생각하면 됩니다."}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Gate Network (Router)"}]},{"type":"text","value":" : 각 토큰이 어떤 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"에 소속되는지를 결정하는 network."}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"img","properties":{"src":"https://github.com/sooftware/sooftware.io/assets/42150335/72ea18a1-d0b9-4d06-ace7-78c013658136","height":350},"children":[]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://arxiv.org/abs/2101.03961"},"children":[{"type":"text","value":"Switch Transformer"}]},{"type":"text","value":"에 아주 좋은 예씨 Figure가 있어서 가져왔습니다. 위 그림처럼 Transformer Block은 Attention -> Add + Norm -> FFN -> Add + Norm과 같은 형태로 이루어져 있습니다. (순서는 아키텍처마다 다를 수 있습니다만 여기서는 넘어가겠습니다.) 여기서 MoE는 "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"FFN"}]},{"type":"text","value":"에 해당하는 layer를 기존과 다르게 사용하는데요, 그림에서처럼 “More”라는 토큰 하나가 들어왔을 때, 이 토큰을 Gate Network (Router)를 거쳐서 N번째 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"에 할당되면, 해당 토큰은 다른 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"experts"}]},{"type":"text","value":"은 제외한 할당된 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"에 해당하는 FFN을 통과하게 됩니다. (밑에서 살펴보겠지만, 위 예시에서는 1개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"만을 할당받았지만, 실제로는 2개 이상의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"expert"}]},{"type":"text","value":"도 보낼 수 있습니다. 😎)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"Sparsity"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"img","properties":{"src":"https://github.com/sooftware/sooftware.io/assets/42150335/d207e623-2e89-4791-a7b3-55d6da7c2bfa","height":140},"children":[]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"여기서 "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Sparsity"}]},{"type":"text","value":"에 대해 보고 넘어가겠습니다. 일반적인 트랜스포머 모델은 dense한 모델입니다. (모든 입력에 대해 모든 입력이 사용되는 모델) 반면에 Sparsity한 모델이란, 모델 파라미터의 일부만 사용할 수 있는 모델을 의미합니다. 즉, 이 MoE 아키텍처는 Sparsity하다고 할 수 있겠죠!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"1개가 아닌 K개의 Expert에게 보내려면 어떻게 해야할까?"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"위에서 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"를 2개 이상에 보낼수도 있다고 했습니다. Mixtral도 1개가 아닌 2개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"에 보내는 방식으로 학습되었는데요, 어떻게 동작하는지 살펴보겠습니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"img","properties":{"src":"https://github.com/sooftware/sooftware.io/assets/42150335/e6c0e658-f46f-4b40-859c-2c9c13ca731a","height":100},"children":[]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"총 8개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"가 있고, 여기서 1개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"로 보내는 문제를 먼저 보겠습니다. 굉장히 간단한 "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Classification"}]},{"type":"text","value":" 문제죠. PyTorch 코드로 구현한다면 아래와 같겠네요."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nn "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"as"}]},{"type":"text","value":" nn\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# inputs는 dim 차원을 가진 tensor"}]},{"type":"text","value":"\ndim"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" num_experts "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"512"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"8"}]},{"type":"text","value":"\ngate "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" nn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"Linear"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"dim"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" num_experts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nnth_expert "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" F"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"softmax"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"gate"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"inputs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dim"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"-"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"argmax"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"이렇게 위와 같이 Linear layer + Softmax 조합으로 간단하게 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"를 특정할 수 있고, 해당 토큰은 특정된 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"로 포워딩해주면 됩니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"그렇다면, 만약에 1개 이상의 K개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"에게 gating을 해주고 싶다면 어떻게 해야할까요? 🤔"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"여러 방법이 있겠지만, Mixtral에서 사용한 Top-k Gating 방식을 소개드리겠습니다. gate network의 linear layer를 H(x)라고 하고, K개의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"에게 보내고 싶다면, 아래와 같은 수식으로 표현할 수 있습니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"img","properties":{"height":70,"alt":"image","src":"https://github.com/sooftware/sooftware.io/assets/42150335/68702730-e153-4a7d-b39f-5eb7c6606f01"},"children":[]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(이해를 위해 K=2를 예시로 들겠습니다.) Linear layer의 결과로 나온 logits에 top 2개의 logits을 뽑고 이 2개의 logits에 대해서 Softmax 함수를 적용합니다. 그럼 이 2개의 expert에 대한 weight 값이 나오게 됩니다!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A라는 Expert에게 0.7, B라는 Expert에게 0.3과 같은 식으로 말이죠. 이렇게 나온 weight를 A와 B Expert를 거쳐서 나온 결과값에 곱해서 사용하게 됩니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"아래는 실제 Mixtral에 사용된 MoE Layer의 구현 코드입니다. 해당 코드에 제가 위에 설명한 내용들에 대해 주석으로 달아놨으니 참고하면서 하나하나 이해해보시는걸 추천드립니다!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(참고) MoE 구현체는 "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/mistralai/mistral-src/blob/main/mistral/moe.py"},"children":[{"type":"text","value":"이곳"}]},{"type":"text","value":"에서 확인 가능합니다. 그리 길지 않아서 코드를 바로 가져왔습니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"MoE Implementation (by Mistral)"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" dataclasses\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" typing "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" List\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" torch\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"functional "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"as"}]},{"type":"text","value":" F\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" simple_parsing"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"helpers "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" Serializable\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"from"}]},{"type":"text","value":" torch "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"import"}]},{"type":"text","value":" nn\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","decorator","annotation","punctuation"]},"children":[{"type":"text","value":"@dataclasses"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dataclass"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"MoeArgs"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"Serializable"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n    num_experts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"text","value":"\n    num_experts_per_tok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"int"}]},{"type":"text","value":"\n\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"class"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"MoeLayer"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"nn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"Module"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"__init__"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" experts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" List"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"nn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"Module"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" gate"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" nn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"Module"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" moe_args"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" MoeArgs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"super"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"__init__"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"assert"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"len"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"experts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":">"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n        self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"experts "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" nn"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"ModuleList"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"experts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n        self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"gate "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" gate\n        self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"args "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" moe_args\n\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"forward"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" inputs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"Tensor"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Step 1 : Expert로 보내기 위한 gate linear layer 통과"}]},{"type":"text","value":"\n        gate_logits "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"gate"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"inputs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Step 2 : gate logits에 대해 Top-K개 Expert 뽑기"}]},{"type":"text","value":"\n        weights"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" selected_experts "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"topk"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"gate_logits"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"args"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"num_experts_per_tok"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Step 3 : Top-K개의 experts에 대한 weights 구하기 (by softmax)"}]},{"type":"text","value":"\n        weights "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" F"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"softmax"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"weights"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dim"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" dtype"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":"torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"float"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"to"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"inputs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"dtype"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n        results "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"zeros_like"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"inputs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# N개의 experts 돌면서 순회"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" expert "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","builtin"]},"children":[{"type":"text","value":"enumerate"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"self"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"experts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Step 4 : i_th expert에 해당하는 tokens 뽑기"}]},{"type":"text","value":"\n            batch_idx"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" nth_expert "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" torch"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"where"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"selected_experts "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Step 5 : i_th expert에 해당하는 token들 i_th expert에 통과"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# Step 6 : 통과된 결과값에 expert weight 반영"}]},{"type":"text","value":"\n            results"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"batch_idx"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" weights"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"batch_idx"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" nth_expert"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","boolean"]},"children":[{"type":"text","value":"None"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"text","value":" expert"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"\n                inputs"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"batch_idx"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" results"}]}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"게이트가 여러 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"에게 라우팅하는 방법을 학습하게 하기 위해서 이렇게 2개 이상의 "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"Expert"}]},{"type":"text","value":"에게 보내도록 학습을 시켰다고 합니다."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"최근에 나온 여러 아키텍처들이 이 MoE 방식에 기반하여 만들어지고 있습니다! 그런만큼 MoE에 대한 이해가 중요한데, 이 포스팅이 도움이 됐으면 좋겠습니다!"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h2","properties":{},"children":[{"type":"text","value":"Reference"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://mistral.ai/news/mixtral-of-experts/"},"children":[{"type":"text","value":"https://mistral.ai/news/mixtral-of-experts/"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://huggingface.co/blog/moe"},"children":[{"type":"text","value":"https://huggingface.co/blog/moe"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://github.com/mistralai/mistral-src"},"children":[{"type":"text","value":"https://github.com/mistralai/mistral-src"}]}]},{"type":"text","value":"\n"}]}],"data":{"quirksMode":false}},"excerpt":"What it MoE? (Mixture of Experts) 현존 최강 LLM인 GPT-4에서 “MoE (Mixture of Experts)” 방식을 채택하여 사용하고 있다고 알려졌는데요, 최근 AI계의 뜨거운 감자 Mistral AI…","fields":{"readingTime":{"text":"9 min read"}},"frontmatter":{"title":"What is MoE? (Mixture of Experts)","userDate":"22 December 2023","date":"2023-12-22T01:11:55.000Z","tags":["nlp","mixtral"],"excerpt":null,"image":{"childImageSharp":{"gatsbyImageData":{"layout":"fullWidth","backgroundColor":"#f8f8f8","images":{"fallback":{"src":"/static/3452aa7dd6375469b11a28016a3738e6/fe3dd/moe.png","srcSet":"/static/3452aa7dd6375469b11a28016a3738e6/1fcf7/moe.png 750w,\n/static/3452aa7dd6375469b11a28016a3738e6/fe3dd/moe.png 881w","sizes":"100vw"},"sources":[{"srcSet":"/static/3452aa7dd6375469b11a28016a3738e6/c473f/moe.webp 750w,\n/static/3452aa7dd6375469b11a28016a3738e6/dfd2e/moe.webp 881w","type":"image/webp","sizes":"100vw"}]},"width":1,"height":0.48240635641316687}}},"author":[{"id":"Soohwan Kim","bio":"Co-founder/A.I. engineer at TUNiB.","avatar":{"children":[{"gatsbyImageData":{"layout":"fullWidth","backgroundColor":"#282838","images":{"fallback":{"src":"/static/a9e6b445142b247ee4cfa66155398bb2/0d6f4/soohwan.png","srcSet":"/static/a9e6b445142b247ee4cfa66155398bb2/248f9/soohwan.png 40w,\n/static/a9e6b445142b247ee4cfa66155398bb2/fd435/soohwan.png 80w,\n/static/a9e6b445142b247ee4cfa66155398bb2/0d6f4/soohwan.png 120w","sizes":"100vw"},"sources":[{"srcSet":"/static/a9e6b445142b247ee4cfa66155398bb2/e7f45/soohwan.webp 40w,\n/static/a9e6b445142b247ee4cfa66155398bb2/589ec/soohwan.webp 80w,\n/static/a9e6b445142b247ee4cfa66155398bb2/71a38/soohwan.webp 120w","type":"image/webp","sizes":"100vw"}]},"width":1,"height":0.6833333333333333}}]}}]}},"relatedPosts":{"totalCount":50,"edges":[{"node":{"id":"6529d72e-80e7-5d61-a672-d66276a3f641","excerpt":"MoE(Mixture of Experts) 기초부터 DeepSeek 혁신까지 작년 이맘때쯤 DeepSeek-V3가 저비용으로 엄청난 성능을 보이면서 화제가 되었습니다. 그 핵심 기술인 MoE(Mixture of Experts…","frontmatter":{"title":"MoE(Mixture of Experts) 기초부터 DeepSeek 혁신까지","date":"2026-01-15T01:11:55.000Z"},"fields":{"readingTime":{"text":"8 min read"},"slug":"/developed-moe/"}}},{"node":{"id":"8b49d3ef-4ce3-568c-9d71-240ff17fc3e0","excerpt":"BERT는 사실 Diffusion 모델이였다?! 최근 굉장히 흥미로운 글을 읽게되어 공유합니다. 원문 : link BERT와 Diffusion이 같은 방식이다?! NLP 연구자들에게 BERT는 너무 익숙한 모델입니다. 201…","frontmatter":{"title":"BERT는 사실 Diffusion 모델이였다?!","date":"2025-10-21T12:00:00.000Z"},"fields":{"readingTime":{"text":"8 min read"},"slug":"/bert_diffusion/"}}},{"node":{"id":"7c7e1676-ea84-58de-970c-ddec9aa10660","excerpt":"RLHF는 수다쟁이를 만든다?! (Does RLHF Breed Verbose Chatterboxes?!) RLHF(Reinforcement Learning from Human Feedback)는 OpenAI의 ChatGPT…","frontmatter":{"title":"RLHF는 수다쟁이를 만든다?! (Does RLHF Breed Verbose Chatterboxes?!)","date":"2024-03-13T01:11:55.000Z"},"fields":{"readingTime":{"text":"7 min read"},"slug":"/rlhf-vervosity/"}}},{"node":{"id":"2b9d3e22-1796-5fab-878d-5941d2e76e9d","excerpt":"LLM Paper Abstract - 2023.12 LLM…","frontmatter":{"title":"LLM Paper Abstract - 2023.12","date":"2024-01-05T10:00:00.000Z"},"fields":{"readingTime":{"text":"5 min read"},"slug":"/llm-abs-202312/"}}},{"node":{"id":"f43fa33b-917b-5c00-8462-937d99592ad7","excerpt":"What it MoE? (Mixture of Experts) 현존 최강 LLM인 GPT-4에서 “MoE (Mixture of Experts)” 방식을 채택하여 사용하고 있다고 알려졌는데요, 최근 AI계의 뜨거운 감자 Mistral AI…","frontmatter":{"title":"What is MoE? (Mixture of Experts)","date":"2023-12-22T01:11:55.000Z"},"fields":{"readingTime":{"text":"9 min read"},"slug":"/moe/"}}}]}},"pageContext":{"slug":"/moe/","prev":{"excerpt":"…","frontmatter":{"title":"당신의 뇌는 최적화를 원한다","tags":["book","review"],"date":"2023-12-10T10:00:00.000Z","draft":false,"excerpt":null,"image":{"childImageSharp":{"gatsbyImageData":{"layout":"fullWidth","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFa0lEQVQ4ywXB7VPahwHA8d9fsYfbQ/eU3bV3a3PLulp8qInt4kNSo0Hj8yM+EZ8R8FkkAioURFF5EBQVURBF1IiC1hg0pu2yi0aT9GK3pOtdb7vri73Zu333+Qg/udHJL7N6+E3+AJfKDLwtneCywk2ybo1US4Qc9yNqtl5QvPyELFeMVEsU0b0VLrfNcLnNxTt1Ft7KG+Bn2X38OKMd4Rfprfwqo4lL2UreLVGTUD1IhWyEeo2buE4P+ZNRWjdOKbJEuanf4CP9ff4kd/Nuow3Z3Jfc1AZ4S9xNfIOJ3+Z0I/z+RiPvV2j4g1hOfI2OW00Gulvu0dJrIVHuQuHcwbJ3ilizhtJ+wGDsGxL6/XzYPU2qfIYP7lq4VKgivsnEO+U6hPcyG8gfChBXriJH7qRUGyClRk+hwkxarZGctmlkk1F6NFu88J8TXT3hWs8iKZoF/ig1cqXehKhhhuvt84iUNoQPPpUgym0lu92BbeUEiWKKgjI1MqmBnh4P2tlDnNtnzIbOeeB7hkW9RokmSK7GT3KbhezhRe6YN6ma/ZyMoUWEq+I6qsbCtDk+Z3b+r4zUj7DQOIDduk3w7Hu2Xv7A1vG/mQhfMLTxNeOrT/lsOkatzs8nTUbkrvv0BQ/p3D9F1GpGSMsqJrdWTUWXjXH3Mevm++zP7TG8/5rK0EOs85McfubDPfOKRsMZptHnjPqfMrS0T8PIMgZnAN/5tzT7Y/xZ0ouQdTuXvJwSZDW9+Jy7HO68YmPrGe3addI1g0Q27/LfHTMvjRG8tQfo82ZpHzvi7M13HO0fs7z3FUObj8nqtxEvUSC0ltegb1Ti7tITGV/j9fE/8dkfsCDux1x0lddzEv635+dBv43xbi/NeTKK9GGevvoX/o0j5mcDGManud4xTGJFE4JP30vEY+bRnI3DERevggfMWw4JFFuIZqWz3RCPd0xLhXWBv+hnyWv38qk2jGv1CVZXiF7bCrKpVe4MWkmtVyIYJ7XYZUWE9Fr8A4P8bdzK5tIRd6V2xqUTzFucZHo83AjFuL10gkju4acp3VQZophc6yjdEWqmQnQthSnu1SEMlKejEyeypusioB0iZndwsbdPf/ALOjSHKIeOuD4SoSn8kpT+ID9PKOZHcUXEtThRuzdRT9iRTziRmSyUSGsRNLnJaO8kYazKxt5cRnignr9HN3nyxSmqxUPEI9sUjkXIUNj49ZWb/O7KNS7Fp1OotjO/tYPRYcPoXULR105ddQmCPicZQ34y9uosvMpyItpazlen+ebhHtNzPrrcUUzeGLcyS/nwvbdJSs3k/Yw8VA4v0dguthkr9zQdKBrKkEsrEYw5H2MuuMZsbQ5ho4oDl4EDWyfbEz3YRk30q4bxTgVokkioLriFQj1Ig8GJYdTEgmMYk6oedUsJvc0Seu7WIfiVOrwtrXhaq/G2V7BmULBh62fT1seKQ8+CWcPyfADniIZ52zAPtxaILFsJOnXMGRRY1S1YVB3YBs24R30Iu/efEQ3EiC6GiHpm2V2e49HuBidfHfDi5JiL0yO+f/Oc796c84+Lp1ycHXH6ZZTHB9vsboXYXA0SWokS8O3jcUcQzA4vVscybqufoCdKeHmfsMfPQXCNk+11vt3x8J9nEX54/oCvo0Eer28Q8S4QdHnxTPqYHJ1Db5jAMDpNv3EKQVrVRmd1C6rCUnTFEvQNzRhy0xgrzWWqqhBvWz3+jhZWu2V4aipwVDdiLZNiyqtgsKCOgao+5LVqmpv11MnNCLdTyshPyKQoIZ2iuBRKRR9TmXSdMlESlYmplH/0CeUJV+nIFCNLuUG5KI0CkZjbSaWIUyrJTiwiM6GEm0mVpCVV8X9A3BATPVxUxAAAAABJRU5ErkJggg=="},"images":{"fallback":{"src":"/static/f792067409ab7c46d76f74bfcdaa30dc/b5658/brain-hormone.png","srcSet":"/static/f792067409ab7c46d76f74bfcdaa30dc/f054e/brain-hormone.png 750w,\n/static/f792067409ab7c46d76f74bfcdaa30dc/b5658/brain-hormone.png 1024w","sizes":"100vw"},"sources":[{"srcSet":"/static/f792067409ab7c46d76f74bfcdaa30dc/4f03f/brain-hormone.webp 750w,\n/static/f792067409ab7c46d76f74bfcdaa30dc/67ded/brain-hormone.webp 1024w","type":"image/webp","sizes":"100vw"}]},"width":1,"height":1}}},"author":[{"id":"Soohwan Kim","bio":"Co-founder/A.I. engineer at TUNiB.","avatar":{"childImageSharp":{"gatsbyImageData":{"layout":"fullWidth","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABYlAAAWJQFJUiTwAAADjElEQVQ4y23Oy48TdQDA8TExEaTttvSBfdHddru7bWc6bWd+8+i0u23n0SdlBRQXZGHDgiiLDwgqXjCIJEaC8cLBmHgwUU9EYzRqQuLJi/4NJB6NF+8evgbOHr7XT76SM5ix7s4QnRHnnm9yZzvBTIswN8JcP5bC67ZoWi7CdtFsn5bloZo+dSNAMYbIIqCmD6mJIVXdR3J6I7r9IQ3T59pZlW+uxzndCbPdC/HZXoq3TikowsfqBOjOmFZ7SrM9p2kfRbXn1O0jKNbsSbJ5BMnu9Gl3+qiiz4OPSvz0QRLHFGwOZH6+neLHT5YRbRerM0J0JrTas/8FZXNKzZgg2es+ZtvDdbs8+iHJl+9lWVP7OG2br26k+PvXJCfmFqoYIpwhTXtMwxpTN0coxhjFmCKbE2rGmKoYPQY9qi2fyzsq//4e5sNXi5TlLqbd5t6lPH/9kuDTG2usqgGi7dO0hzSsIXUzQDaGKGKMLEZUxZCKCJB02+PUpMH9vQwP7ybYnSxyfNrjwumA3dEiD94v8cfnK7xzWsbpujQtH9X0qBs+iuEjC5+a7lPVPSqai9SyelyYFbjkh5hqC3TkKOutLON2nkYpgtuMcT6IszdPslo8SLlcpmUH1A0XRQyQhUtNuFQ1l4o2QFI1h3OTVXbcg+grIfSVBRqlEGopgrYSRi0e4KiIse1mScSeopA/iLADmoZL3Rgg631q+oCq1qeq95FOzhQefpzn7eMpBmqcoBVj04pzwkky0eNMRYIdL8F3twusLe2nslrE6g5pGX1U8/FhD1nvUW1tUJK7SH9+n+DR1zF2vQSvH0lz88wiV45V2J1WuHqsxLXNAnuzNJdfWmK5/BylUgFhb6DZAxR9g7rpIos+Wttja2uE9M9vYb69k+DqfJErWzLOuoVqdKlpDo4jODms4zlFckuHObx4iHwuRi6fYqmYY201x/LqMrnFDNl8gRvvukhNdT9394rcOlNFMxrUhYFmW9imTEsp0mhWKC2nWSokyWSiFA7HSKcXiEb34fayyLVniUQk8rmn2drKIqlqiNcuVrh2ymQS1Nh8sc/GoMEbl7u8eb5D1yqTzkRJJsOkkiGymQVShyLE4yHWKnEq1RjpTIhmI8r2y3mkyloI38uha1n6bpVXrkw5+4LD/S/2uHnrIopaJhZ9hmQqwqHkAXJP8BDhyD46ZoWdMxOGcx/PNfECk/8AbxXdRjRliPoAAAAASUVORK5CYII="},"images":{"fallback":{"src":"/static/a9e6b445142b247ee4cfa66155398bb2/7cf1f/soohwan.png","srcSet":"/static/a9e6b445142b247ee4cfa66155398bb2/34f77/soohwan.png 750w,\n/static/a9e6b445142b247ee4cfa66155398bb2/a94f6/soohwan.png 1080w,\n/static/a9e6b445142b247ee4cfa66155398bb2/7cf1f/soohwan.png 1148w","sizes":"100vw"},"sources":[{"srcSet":"/static/a9e6b445142b247ee4cfa66155398bb2/38420/soohwan.webp 750w,\n/static/a9e6b445142b247ee4cfa66155398bb2/7470d/soohwan.webp 1080w,\n/static/a9e6b445142b247ee4cfa66155398bb2/b5ef6/soohwan.webp 1148w","type":"image/webp","sizes":"100vw"}]},"width":1,"height":0.6829268292682927}}}}]},"fields":{"readingTime":{"text":"5 min read"},"layout":"","slug":"/brain-hormone/"}},"next":{"excerpt":"# 원씽 (THE ONE THING) 원씽(The One Thing)은 2013년에 나온 책이고, 아마존 베스트셀러…","frontmatter":{"title":"원씽 (THE ONE THING)","tags":["book","review"],"date":"2023-12-26T10:00:00.000Z","draft":false,"excerpt":null,"image":{"childImageSharp":{"gatsbyImageData":{"layout":"fullWidth","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFgklEQVQ4yxXKe0zUhwHA8V+2ZFmzxTRtbF3crEwUlLcHx+uQe3oPKByPE+/kcS/gjjvgeB/cDXndHago5SVSQDxUdD66TqzVgmJlmC221DWS2qqbmWnco9n7jy6m38U/vv988hXkMgdKRQ2Kl8kdKJUu5PIa5IoalOpa1PoGFIY29uY0oH5pcgcquQOFrBqZtJq9e90o5E6kWZXIsqsQIl6JYcfrYmIjc9mxMYPITZmIlUYSM/LZmZ5PqslCoqmazKR9pGzVELtFw7bXsoiN0JIcW0DsZhXibVKSf57JtlfiEFIiJCRvU5EQX4ooq5JMqZGKhlq0lVZyWlyYDjXjHe/EYzBTkFJIjq4eTVEL2XmtqE0dqNUOJMn7SY5SEbkhGSH6LTW7d2g5YK7H0jGAKseMSFmILeihY7aN335xgo7Rfk6PdLAUtNJeYsKSU4G1wotOXk2uyoZCVUNcVCG7E/QIKW/7kJSHkOismB0ONGVmskstDF7s5PGTSRYW5/ihxIrY2siTTyZ4ttDGfKORTqMJtchITJydpHQ3cRIPCdJ6BJ01iDq/hQp3DyarnRKnnYGzfh4+mubSzbP8QFrJRn0rSbZjvJHjxhEMYvD3cTHcx3t9DswlHlLye8h2TqNpO4dgPfwexRoLJZPLKMtD2I+Oc3BuDGPfO+Q56oje50BQe0l2TfCq3ktq4wSJ7WfIH7pM99wvqT00hTLPh841gSF4CsF36xm17eMYfNPozV1o+y8R5R5ku62NSFsvct8E0uBF0jomkHVNUTR8Bf+H61hO30ceuIMicAuz9yRp2a1EiwoQDAdHUKXaaSpx03x4hjhvGHnPMNaJGY7dXmfh62+5/c3/+PXT/zD92dfID11G4R9D1TlJUsNxSo9cxztzhVJ7N0kR+xBiXpPQVOphdukegeU/YJ3/lLT2eY5dus3AqWuUtc0QfvJvxi7e4cbSbSZ//xeaQn4qvG1EusY5//A5vcvrlPWEcBTVItg1JbgGzyHpvUHf1d8x9JtHBOcXWfrqOea+8wSPzHL/Xy9Y//ILbn28zI2nf6P7/VWSW+epDd/l+uo9fDNL7K6up7mqCqGurIYj410UeH04D7VjH55m5voKwQurJJSdYOXRc/j7PfjTab7950Me/OO/TK0+Zl/gFMOLy4ycfB9z1whlTXZ+4a5HyNEf4GSPmzuTTdgDLUhc3ZxYvEd14wjf/54Il2cI/hjmq7vneb52jb+++I7xG2t0zxzFf7KN/rk5NJU9vHu0jpqafgStyYktz8NRbzNtIz5svg5CZw+j1RjZ9WYWNQYXs/0hfnVpgUdPv+GDzz+iaWIAf3iU0WtzFOVYsDmd+LsGiUqwI0gth/GPXaDcbMddV89QOMDC51NUlRYS9RMZdQ4/xbZBdKUD3Fxd4vpnYaauhbDVduB2+cndnU+F6gDZeyzEJxQiJKQoMTS2MDo6wNqnZwjPvcs702eodPjYtEHElrd0vP5jMeL4Am4uLvDdi8fw4j63rs7S4GnHUlGJum6Q/Q3DlHVdQNDaOskrL6e1uBn/weOoq0JsSbCwNdHM1ngz2xPLSZbYsVZ3s7KyyJ+f3WVs9DjLX67Qf/4E3dO9qCsq0RobiUkqQRDldpGtr0Vj7SVR34VUW4XOM8T+zlMEp8Y5d3mYtbWzrD+4zCcPrnD141lydAfYs9eFrsiBWGZAIslnV6ScHZvECJuEzfx0QyLRIisxscXsySolO9dGls5KfaCL8SszhMYD2LxBNI5jqE3tSBVmdr0RT8TGdLa/mUL05jR27tTzsx/FIEhSDGSKiklPKiItsZD01HKkUhuZYiOZMid51gAFloPIdM1k7HGSnlZBmrgMSXo5klQTGaJiMlP3k/HyFxXzf83Km8gZTBIwAAAAAElFTkSuQmCC"},"images":{"fallback":{"src":"/static/4fe4642c37a53e0539fdbf38143cbdc8/b5658/one-thing.png","srcSet":"/static/4fe4642c37a53e0539fdbf38143cbdc8/f054e/one-thing.png 750w,\n/static/4fe4642c37a53e0539fdbf38143cbdc8/b5658/one-thing.png 1024w","sizes":"100vw"},"sources":[{"srcSet":"/static/4fe4642c37a53e0539fdbf38143cbdc8/4f03f/one-thing.webp 750w,\n/static/4fe4642c37a53e0539fdbf38143cbdc8/67ded/one-thing.webp 1024w","type":"image/webp","sizes":"100vw"}]},"width":1,"height":1}}},"author":[{"id":"Soohwan Kim","bio":"Co-founder/A.I. engineer at TUNiB.","avatar":{"childImageSharp":{"gatsbyImageData":{"layout":"fullWidth","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABYlAAAWJQFJUiTwAAADjElEQVQ4y23Oy48TdQDA8TExEaTttvSBfdHddru7bWc6bWd+8+i0u23n0SdlBRQXZGHDgiiLDwgqXjCIJEaC8cLBmHgwUU9EYzRqQuLJi/4NJB6NF+8evgbOHr7XT76SM5ix7s4QnRHnnm9yZzvBTIswN8JcP5bC67ZoWi7CdtFsn5bloZo+dSNAMYbIIqCmD6mJIVXdR3J6I7r9IQ3T59pZlW+uxzndCbPdC/HZXoq3TikowsfqBOjOmFZ7SrM9p2kfRbXn1O0jKNbsSbJ5BMnu9Gl3+qiiz4OPSvz0QRLHFGwOZH6+neLHT5YRbRerM0J0JrTas/8FZXNKzZgg2es+ZtvDdbs8+iHJl+9lWVP7OG2br26k+PvXJCfmFqoYIpwhTXtMwxpTN0coxhjFmCKbE2rGmKoYPQY9qi2fyzsq//4e5sNXi5TlLqbd5t6lPH/9kuDTG2usqgGi7dO0hzSsIXUzQDaGKGKMLEZUxZCKCJB02+PUpMH9vQwP7ybYnSxyfNrjwumA3dEiD94v8cfnK7xzWsbpujQtH9X0qBs+iuEjC5+a7lPVPSqai9SyelyYFbjkh5hqC3TkKOutLON2nkYpgtuMcT6IszdPslo8SLlcpmUH1A0XRQyQhUtNuFQ1l4o2QFI1h3OTVXbcg+grIfSVBRqlEGopgrYSRi0e4KiIse1mScSeopA/iLADmoZL3Rgg631q+oCq1qeq95FOzhQefpzn7eMpBmqcoBVj04pzwkky0eNMRYIdL8F3twusLe2nslrE6g5pGX1U8/FhD1nvUW1tUJK7SH9+n+DR1zF2vQSvH0lz88wiV45V2J1WuHqsxLXNAnuzNJdfWmK5/BylUgFhb6DZAxR9g7rpIos+Wttja2uE9M9vYb69k+DqfJErWzLOuoVqdKlpDo4jODms4zlFckuHObx4iHwuRi6fYqmYY201x/LqMrnFDNl8gRvvukhNdT9394rcOlNFMxrUhYFmW9imTEsp0mhWKC2nWSokyWSiFA7HSKcXiEb34fayyLVniUQk8rmn2drKIqlqiNcuVrh2ymQS1Nh8sc/GoMEbl7u8eb5D1yqTzkRJJsOkkiGymQVShyLE4yHWKnEq1RjpTIhmI8r2y3mkyloI38uha1n6bpVXrkw5+4LD/S/2uHnrIopaJhZ9hmQqwqHkAXJP8BDhyD46ZoWdMxOGcx/PNfECk/8AbxXdRjRliPoAAAAASUVORK5CYII="},"images":{"fallback":{"src":"/static/a9e6b445142b247ee4cfa66155398bb2/7cf1f/soohwan.png","srcSet":"/static/a9e6b445142b247ee4cfa66155398bb2/34f77/soohwan.png 750w,\n/static/a9e6b445142b247ee4cfa66155398bb2/a94f6/soohwan.png 1080w,\n/static/a9e6b445142b247ee4cfa66155398bb2/7cf1f/soohwan.png 1148w","sizes":"100vw"},"sources":[{"srcSet":"/static/a9e6b445142b247ee4cfa66155398bb2/38420/soohwan.webp 750w,\n/static/a9e6b445142b247ee4cfa66155398bb2/7470d/soohwan.webp 1080w,\n/static/a9e6b445142b247ee4cfa66155398bb2/b5ef6/soohwan.webp 1148w","type":"image/webp","sizes":"100vw"}]},"width":1,"height":0.6829268292682927}}}}]},"fields":{"readingTime":{"text":"7 min read"},"layout":"","slug":"/one-thing/"}},"primaryTag":"nlp"}},
    "staticQueryHashes": ["3170763342","3229353822"]}