avatarMaya Akim

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4872

Abstract

nd prompting Arthur Mensch, CEO of Mistral, to remove the problematic clause.</p> <figure id="4daa"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//twitter.com/arthurmensch/status/1734470462451732839%3Fs%3D20&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fabs.twimg.com%252Ferrors%252Flogo46x38.png%26key%3Da19fcc184b9711e1b4764040d3dc5c07" allowfullscreen="" frameborder="0" height="281" width="500"> </div> </div> </figure></iframe></div></div></figure><p id="86d1">Lastly, to address the elephant in the room: Mistral isn’t a GitHub repository that drew a vast number of programmers tirelessly working to release a smart open-source LLM. Instead, it’s a company that raised over <a href="https://techcrunch.com/2023/12/11/mistral-ai-a-paris-based-openai-rival-closed-its-415-million-funding-round/?guccounter=1">500 million</a> in 2023 alone, with Bloomberg valuing the company at roughly <a href="https://mercury.bloomberg.com/images/405322296">2 billion</a>. Their choice not to release the training code, documentation, and dataset — in other words, keeping the model relatively closed-source — is a strategy for Mistral to maintain its competitive edge.</p><p id="7278">So to sum things up, Mixtral-8x7B is <b><i>the best open-weights model</i></b> that outperforms GPT3.5 and Llama 2 70B on most benchmarks.</p><h1 id="5b09">What is Mixture of Experts (MoE) Anyway?</h1><p id="f2c0">Let me remind you again of Mistral’s definition of the model:</p><blockquote id="5a42"><p><i>a high-quality <b>sparse mixture of experts model (SMoE)</b> with open weights</i>”.</p></blockquote><p id="7029">A lot of us (myself included) encountered this term for the first time thanks to the release of Mixtral. To TLDR it for you:</p><p id="45eb">MoEs originated from a <a href="https://www.cs.toronto.edu/~hinton/absps/jjnh91.pdf">1991 research paper </a>where a system uses <b>multiple neural networks.</b> These networks, or ‘experts’, are selected by a <b>gating network</b> that assigns their <b>roles and weights</b>. Both experts and the gating network are trained together to effectively handle diverse training cases.</p><figure id="ec1d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*uSkP3yw0Pp4V_SPHPVbejw.png"><figcaption>MoE layer from the Outrageously Large Neural Network paper</figcaption></figure><p id="7463">For anyone interested going into more depth, I suggest this <a href="https://huggingface.co/blog/moe">HuggingFace article.</a></p><p id="5025">Sparsity in MoEs means that only <b><i>parts of the network</i></b> are active <b><i>for specific inputs</i></b>, allowing scaling without increasing total computation.</p><h2 id="c6eb">Pros of sparse MoEs:</h2><ol><li><b>Efficient Pretraining</b>: MoEs allow for faster and more compute-efficient. This means <a href="https://huggingface.co/google/switch-c-2048">larger models</a> or datasets can be trained with the <i>same computing budget</i>.</li><li><b>Faster Inference</b>: Although MoEs have many parameters, only a subset is active during inference, leading to <i>quicker processing</i>.</li></ol><h2 id="ae50">Cons of sparse MoEs:</h2><ol><li><b>Fine-Tuning</b>: sparse MoEs historically struggle with fine-tuning, often leading to overfitting, although <a href="https://arxiv.org/pdf/2305.14705.pdf">recent research</a> gives a lot of hope.</li><li><b>Memory Requirements</b>: All parameters of MoEs need to be loaded into memory, requiring substantial VRAM.</li><li><b>Load Balancing</b>: Ensuring even distribution of computation across experts is a challenge, often addressed by auxiliary loss functions and expert capacity thresholds.</li></ol><h1 id="97ce">How To Run it Locally</h1><p id="1622">2 most popular ways are:</p><h2 id="9cc2">VLLM</h2><div id="1433" class="link-block"> <a href="https://github.com/vllm-project/vllm/issues/1991"> <div> <div> <h2>Add Mixture of Experts: Mixtral 8x 7B release · Issue #1991 · vllm-project/vllm</h2> <div><h3>Mistral AI released their new model called Mixtral which is an MoE architecture based on MegaBlocks. It includes 8…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*QvHrtfs08p-4dTnm)"></div> </div> </div> </a> </div><h2 id="5574">and LM Studio</h2><div id="35e2" class="link-block"> <a href="https://lmstudio.ai/"> <div> <div>

Options

          <h2>👾 LM Studio - Discover and run local LLMs</h2>
            <div><h3>LM Studio is an easy to use desktop app for experimenting with local and open-source Large Language Models (LLMs). The…</h3></div>
            <div><p>lmstudio.ai</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*wrcqbq68WvHRMNz6)"></div>
          </div>
        </div>
      </a>
    </div><h1 id="a68c">Mixtral-8x7B Demos</h1><p id="1f49">If you’d like to test out Mixtral but you don’t have an option to run it locally, here’s a list of the best platforms that offers Mixtral inference:</p><h2 id="9bd0">Perplexity labs</h2><figure id="d07a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*S8HBsiPol-ZcX6VbAa93SA.png"><figcaption>Screenshot of perplexity labs</figcaption></figure><h2 id="5c48">Vercel</h2><figure id="1ec1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*M9s9yv5F_Ae3TfWmM9I42g.png"><figcaption>Screenshot of Vercel AI</figcaption></figure><h2 id="1759">Replicate</h2><figure id="eee8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_xR3t9xiwgAEPtu601flKA.png"><figcaption>Screenshot of Replicate</figcaption></figure><h1 id="87f1">Platform API endpoints</h1><p id="1826">Mistral AI currently provides access to Large Language Models through an <a href="https://docs.mistral.ai/platform/pricing">pay-as-you-go API</a>. It’s in beta right now and however wants access has to join the waitlist first.</p><p id="4b68">Mistral <a href="https://docs.mistral.ai/platform/endpoints">offers 3 models</a> for endpoints:</p><ol><li><b><i>mistral-tiny — </i></b>Mistral-7B-v0.2, a better fine-tuning of the initial Mistral-7B released. The most affordable model</li><li><b><i>mistral-small — </i></b>Mixtral-8X7B-v0.1, excellent choice for code generation and multilanguage output</li><li><b><i>mistral-medium — </i></b>This model is a mystery and many speculate that its <a href="https://www.reddit.com/r/LocalLLaMA/comments/18fq00r/mistral_has_an_even_more_powerfull_model_in_the/?utm_source=share&amp;utm_medium=web2x&amp;context=3">performance might match GPT4</a></li><li><b><i>mistral-embed — </i></b>Embeddings models for retrieval and RAG</li></ol><p id="3eb4">Mistral AI provides client codes in both <a href="https://docs.mistral.ai/platform/client">Python and Javascript</a>. For the sake of simplicity I’ll share the client code in Python, but you can find javascript code in their docs:</p><h2 id="22d8">Chat Completion</h2><div id="b6d1"><pre><span class="hljs-keyword">from</span> mistralai.client <span class="hljs-keyword">import</span> MistralClient

<span class="hljs-keyword">from</span> mistralai.models.chat_completion <span class="hljs-keyword">import</span> ChatMessage

api_key = os.environ[<span class="hljs-string">"MISTRAL_API_KEY"</span>] model = <span class="hljs-string">"mistral-tiny"</span>

client = MistralClient(api_key=api_key)

messages = [ ChatMessage(role=<span class="hljs-string">"user"</span>, content=<span class="hljs-string">"What is the best French cheese?"</span>) ]

<span class="hljs-comment"># No streaming</span> chat_response = client.chat( model=model, messages=messages, )

<span class="hljs-comment"># With streaming</span> <span class="hljs-keyword">for</span> chunk <span class="hljs-keyword">in</span> client.chat_stream(model=model, messages=messages): <span class="hljs-built_in">print</span>(chunk)</pre></div><h2 id="d575">Embeddings</h2><div id="13c7"><pre><span class="hljs-keyword">from</span> mistralai.client <span class="hljs-keyword">import</span> MistralClient

api_key = os.environ[<span class="hljs-string">"MISTRAL_API_KEY"</span>] client = MistralClient(api_key=api_key)

embeddings_batch_response = client.embeddings( model=<span class="hljs-string">"mistral-embed"</span>, <span class="hljs-built_in">input</span>=[<span class="hljs-string">"Embed this sentence."</span>, <span class="hljs-string">"As well as this one."</span>], )</pre></div><h1 id="12b5">Conclusion</h1><p id="f125">Mixtral 8x7B stands out as an exceptional open-weights model. The Mistral team appears deeply attuned to their customers’ needs, consistently delivering products that resonate with a wide audience through clever, yet relatively low-key marketing strategies.</p><p id="02af">After several years of OpenAI’s market dominance, Mistral’s API access is set to offer millions of developers greater choice, enabling them to select the model that best meets their needs. With substantial funding behind them, we can anticipate not only amazing models from Mistral but also a potential shift towards more closed-source LLMs. I’m genuinely excited about Mistral and can’t wait to see what’s next!</p></article></body>

Everything About MISTRAL’S Mixtral-8x7B: The Best Open LLM

Mistral’s blog that announced the latest model

Every December, machine learning experts gather at the annual NeurIPS conference to discuss the latest and greatest achievements in ML. This influential event makes late November and early December an ideal time for AI startups to launch their products.

ChatGPT revolutionized the AI landscape with its launch on November 30, 2022. Following this, Google introduced its controversial model, Gemini, on December 6th 2023. Just a few days later, Mistral announced their latest model. They shared a torrent magnet link on Twitter, a genius marketing strategy that made the team very popular with the community.

Best Open Source Model So Far?

When it comes to performance, Mixtral seemingly matches or surpasses GPT-3.5 and Llama 2 70B on most benchmarks, while offering 6X faster inference compared to Llama 2.

Source: Mistral’s blog

Its notable features include:

  • A context window of 32,000 tokens
  • Compatibility with English, French, Italian, German, & Spanish
Mixtral 8x7B masters French, German, Spanish, Italian, and English.
  • Excellent code generation capabilities
  • Capability for fine-tuning into an instruction-following model
  • Less hallucination and biases
Compared to Llama 2, Mixtral is more truthful (73.9% vs 50.2% on the TruthfulQA benchmark) and presents less bias on the BBQ benchmark.

Furthermore, Mixtral has been released under the permissive Apache 2.0 license. Unlike some of OpenAI’s closed-source models, we can see the total parameter count of this model.

With its impressive performance and features, various newsletters, AI influencers, and blog posts have heralded Mixtral as the ‘Best Open-Source Model Ever’ often using hype-inducing titles like ‘Open-source AI on the rise.’

But is it REALLY open source? Let’s take a step back and examine.

In their blog, Mistral’s team defines Mixtral 8x7B as:

a high-quality sparse mixture of experts model (SMoE) with open weights”.

Interestingly, Mistral doesn’t label their model as ‘open-source,’ but rather as an ‘open-weights’ model. As Andrej Karpathy, an AI expert at OpenAI, points out for a model to be truly open-source, it should also include access to the training code, dataset, and documentation — elements Mistral hasn’t shared.

Furthermore, Mistral’s Terms of Service initially prohibited using Mixtral’s outputs for anything other than fine-tuning their models. This restriction did not sit well with the public, leading to backlash and prompting Arthur Mensch, CEO of Mistral, to remove the problematic clause.

Lastly, to address the elephant in the room: Mistral isn’t a GitHub repository that drew a vast number of programmers tirelessly working to release a smart open-source LLM. Instead, it’s a company that raised over $500 million in 2023 alone, with Bloomberg valuing the company at roughly $2 billion. Their choice not to release the training code, documentation, and dataset — in other words, keeping the model relatively closed-source — is a strategy for Mistral to maintain its competitive edge.

So to sum things up, Mixtral-8x7B is the best open-weights model that outperforms GPT3.5 and Llama 2 70B on most benchmarks.

What is Mixture of Experts (MoE) Anyway?

Let me remind you again of Mistral’s definition of the model:

a high-quality sparse mixture of experts model (SMoE) with open weights”.

A lot of us (myself included) encountered this term for the first time thanks to the release of Mixtral. To TLDR it for you:

MoEs originated from a 1991 research paper where a system uses multiple neural networks. These networks, or ‘experts’, are selected by a gating network that assigns their roles and weights. Both experts and the gating network are trained together to effectively handle diverse training cases.

MoE layer from the Outrageously Large Neural Network paper

For anyone interested going into more depth, I suggest this HuggingFace article.

Sparsity in MoEs means that only parts of the network are active for specific inputs, allowing scaling without increasing total computation.

Pros of sparse MoEs:

  1. Efficient Pretraining: MoEs allow for faster and more compute-efficient. This means larger models or datasets can be trained with the same computing budget.
  2. Faster Inference: Although MoEs have many parameters, only a subset is active during inference, leading to quicker processing.

Cons of sparse MoEs:

  1. Fine-Tuning: sparse MoEs historically struggle with fine-tuning, often leading to overfitting, although recent research gives a lot of hope.
  2. Memory Requirements: All parameters of MoEs need to be loaded into memory, requiring substantial VRAM.
  3. Load Balancing: Ensuring even distribution of computation across experts is a challenge, often addressed by auxiliary loss functions and expert capacity thresholds.

How To Run it Locally

2 most popular ways are:

VLLM

and LM Studio

Mixtral-8x7B Demos

If you’d like to test out Mixtral but you don’t have an option to run it locally, here’s a list of the best platforms that offers Mixtral inference:

Perplexity labs

Screenshot of perplexity labs

Vercel

Screenshot of Vercel AI

Replicate

Screenshot of Replicate

Platform API endpoints

Mistral AI currently provides access to Large Language Models through an pay-as-you-go API. It’s in beta right now and however wants access has to join the waitlist first.

Mistral offers 3 models for endpoints:

  1. mistral-tiny — Mistral-7B-v0.2, a better fine-tuning of the initial Mistral-7B released. The most affordable model
  2. mistral-small — Mixtral-8X7B-v0.1, excellent choice for code generation and multilanguage output
  3. mistral-medium — This model is a mystery and many speculate that its performance might match GPT4
  4. mistral-embed — Embeddings models for retrieval and RAG

Mistral AI provides client codes in both Python and Javascript. For the sake of simplicity I’ll share the client code in Python, but you can find javascript code in their docs:

Chat Completion

from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage

api_key = os.environ["MISTRAL_API_KEY"]
model = "mistral-tiny"

client = MistralClient(api_key=api_key)

messages = [
    ChatMessage(role="user", content="What is the best French cheese?")
]

# No streaming
chat_response = client.chat(
    model=model,
    messages=messages,
)

# With streaming
for chunk in client.chat_stream(model=model, messages=messages):
    print(chunk)

Embeddings

from mistralai.client import MistralClient

api_key = os.environ["MISTRAL_API_KEY"]
client = MistralClient(api_key=api_key)

embeddings_batch_response = client.embeddings(
      model="mistral-embed",
      input=["Embed this sentence.", "As well as this one."],
  )

Conclusion

Mixtral 8x7B stands out as an exceptional open-weights model. The Mistral team appears deeply attuned to their customers’ needs, consistently delivering products that resonate with a wide audience through clever, yet relatively low-key marketing strategies.

After several years of OpenAI’s market dominance, Mistral’s API access is set to offer millions of developers greater choice, enabling them to select the model that best meets their needs. With substantial funding behind them, we can anticipate not only amazing models from Mistral but also a potential shift towards more closed-source LLMs. I’m genuinely excited about Mistral and can’t wait to see what’s next!

Llm
Mistral
Open Source
AI
Neural Networks
Recommended from ReadMedium