<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Refact AI</title>
    <description>The latest articles on Forem by Refact AI (@refact_ai).</description>
    <link>https://forem.com/refact_ai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1065157%2F8a22a585-cb15-403e-a549-d71eea27ad33.jpg</url>
      <title>Forem: Refact AI</title>
      <link>https://forem.com/refact_ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/refact_ai"/>
    <language>en</language>
    <item>
      <title>Open-source Fine-Tuning on Codebase with Refact</title>
      <dc:creator>Refact AI</dc:creator>
      <pubDate>Tue, 05 Sep 2023 10:18:54 +0000</pubDate>
      <link>https://forem.com/refact/open-source-fine-tuning-on-codebase-with-refact-3po1</link>
      <guid>https://forem.com/refact/open-source-fine-tuning-on-codebase-with-refact-3po1</guid>
      <description>&lt;p&gt;Code completion has become increasingly popular, thanks to tools like GitHub Copilot and open-source Large Language Models (LLMs). However, both Copilot and open models often fall short when it comes to working effectively on your specific codebase. This is because these models have never been exposed to your unique code patterns and conventions.&lt;br&gt;
In order to improve the quality of suggestions and tailor them to your codebase there's a technique called fine-tuning. By fine-tuning a pre-trained model on your codebase, you can improve its ability to understand and generate code that aligns with your requirements.&lt;br&gt;
In this blog post, we will delve into the concept of fine-tuning, and its technical details, and show how you can start self-hosting your fine-tuned model in Refact.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;&lt;br&gt;
    &lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;In this video, the same simple function is generated by: Copilot, base Refact 3b model, fine-tuned Refact 3b model.&lt;br&gt;
All three can look down the code, find what variables are necessary, and help you with typing, but only the finetuned version knows how to work with DatasetOpts.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Exactly Fine-tune Works?
&lt;/h2&gt;

&lt;p&gt;Large language models work by predicting the next token. This simple objective allows LLMs to learn syntax, code patterns, and even high-level concepts.&lt;br&gt;
The code you write is probably different from all the other projects on the internet. It might be similar - that's why code LLMs are already useful - but you probably have your own established way to do things.&lt;br&gt;
One simple example is coding style. Predicting the next token in a certain way defines how a model writes code, including variable names, spaces, etc.&lt;br&gt;
Fine-tuning has the same objective as pre-training: predict the next token. By adjusting the parameters in a clever way (it needs only one GPU to train!), the model starts to predict the next token according to your coding style, as well as patterns, your typical API usage, etc.&lt;br&gt;
That's why you'll see more useful suggestions if you are using a fine-tuned model.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Data Can I Use for Fine-tuning the Model?
&lt;/h2&gt;

&lt;p&gt;In Refact UI, you will need to upload source code, in archive form (.zip, .tar.gz, .bz2) or give it a link to a git repository (private git repositories work too, you need to generate a ssh key though). You can upload an individual file, too. Refact then will slice your source code into pieces that a model can actually train on.&lt;br&gt;
It's a good idea to give the model the current code of your projects. However, it's NOT a good idea to feed 3rd party libraries that you use, as the model may learn to generate code similar to the internals of those libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Loss
&lt;/h2&gt;

&lt;p&gt;In order to measure how well the model is adapted to your code, you can take one or two of your files and make it a test set. To be meaningful as a measurement, these files should be using your coding style, your libraries and APIs.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://refact.ai/images/blog/refact-finetune/sources-code.png"&amp;gt;
&amp;lt;span&amp;gt;Picture: shows &amp;lt;code&amp;gt;vllm&amp;lt;/code&amp;gt; github repository as a training set, and a single file &amp;lt;code&amp;gt;benchmark_serving.py&amp;lt;/code&amp;gt; as a fixed test set&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If test files are also present in the train set, they will be automatically subtracted from it.&lt;br&gt;
If you don't specify any test set, it will pick several random files for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technical Details
&lt;/h2&gt;

&lt;p&gt;It's possible to fine-tune all parameters (called "full fine-tune"), but recently PEFT methods became popular. PEFT stands for Parameter-Efficient Fine-Tuning. There are several methods available, the most popular so far is LoRA (&lt;a href="https://arxiv.org/abs/2106.09685"&gt;2106.09685&lt;/a&gt;) that can train less than 1% of the original weights.&lt;br&gt;
LoRA has one important parameter -- tensor size, called &lt;code&gt;lora_r&lt;/code&gt;. It defines how much information LoRA can add to the network. If your codebase is small, the fine-tuning process will see the same data over and over again, many times in a loop. We found that for a smaller codebase small LoRA tensors work best because it won't overfit as much -- the tensors just don't have the capacity to fit the limited training set exactly.&lt;br&gt;
As the codebase gets bigger, tensors should become bigger as well. We also unfreeze token embeddings at a certain codebase size.&lt;br&gt;
To pick all the parameters automatically, we have developed a heuristic that calculates a score based on the source files it sees. This score is then used to determine the appropriate LoRA size, number of finetuning steps, and other parameters. We have tested this heuristic on several beta test clients, small codebases of several files, and large codebases like the Linux kernel (consisting of about 50,000 useful source files).&lt;br&gt;
If the heuristic doesn't work for you for whatever reason, you can set all the parameters yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Test If It Worked?
&lt;/h2&gt;

&lt;p&gt;After the fine-tuning process finishes (which should take several hours), you can dynamically turn it on and off and observe the difference it makes for code suggestions. You can do this using this switch:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://refact.ai/images/blog/refact-finetune/lora-select.png"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;There's a catch: both VS Code and JB plugins cache the responses. To force the model to produce a new suggestion (rather than immediately responding with a cached one), you can change the text a few lines above, for example, a comment.&lt;br&gt;
Alternatively, you can use the Manual Suggestion Trigger (a key combination), which always produces a new suggestion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Self Hosting
&lt;/h2&gt;

&lt;p&gt;You can use your own GPU to host and fine-tune LLMs with &lt;a href="https://github.com/smallcloudai/refact/"&gt;Refact self-hosting server&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;Q: Maybe models can guess code better if they have more context, especially from other files?&lt;br&gt;
A: For the best results, you need both. Fine-tuning gives you the coding style, and if the model can see relevant snippets of code from other files, it will work better for calling functions and using types defined outside of the current file. We are currently working on that, too. Join our discord server and be the first to know when we release it!&lt;br&gt;
Q: I only want to imitate the coding style of certain experts on my team. Is this possible?&lt;br&gt;
A: Certainly! It is indeed possible to imitate the coding style of specific experts on your team. You can achieve this by selectively uploading the files that represent the desired coding style and excluding any old or low-quality code. By doing so, the model will generate code that aligns with the chosen coding style. This approach can be valuable in transferring expert knowledge within your company, as the coding assistant can consistently suggest good coding practices.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>ai</category>
      <category>opensource</category>
      <category>selfhost</category>
    </item>
    <item>
      <title>🤖We trained a small 1.6b code model that reaches 32% HumanEval🤖</title>
      <dc:creator>Refact AI</dc:creator>
      <pubDate>Tue, 05 Sep 2023 10:15:23 +0000</pubDate>
      <link>https://forem.com/refact/we-trained-16b-code-model-and-you-can-use-it-as-a-personal-copilot-in-refact-for-free-12io</link>
      <guid>https://forem.com/refact/we-trained-16b-code-model-and-you-can-use-it-as-a-personal-copilot-in-refact-for-free-12io</guid>
      <description>&lt;p&gt;Today we're introducing Refact LLM: 1.6B code model with infill real-time code completion (including fill-in-the-middle(FIM) capability) and chat.&lt;br&gt;
Refact LLM achieves the state-of-the-art performance among the code LLMs, coming closer to  HumanEval as Starcoder, being 10x smaller in size, and it beats other code models such as StableCode, CodeGen and ReplitCode on HumanEval metric. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;1.6b parameters&lt;/li&gt; 
    &lt;li&gt;20 programming languages&lt;/li&gt; 
    &lt;li&gt;4096 tokens context&lt;/li&gt; 
    &lt;li&gt;code completion and chat capabilities&lt;/li&gt; 
    &lt;li&gt;SoTA on HumanEval benchmark among similar code models&lt;/li&gt; 
    &lt;li&gt;pre-trained on permissive licensed code and available for commercial use&lt;/li&gt; 
&lt;/ul&gt;


    &lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;Model&lt;/th&gt;
                &lt;th&gt;Model Size&lt;/th&gt;
                &lt;th&gt;HumanEval pass@1&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td&gt;DeciCoder-1b&lt;/td&gt;
                &lt;td&gt;1b&lt;/td&gt;
                &lt;td&gt;19.1%&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;Refact-1.6-fim&lt;/td&gt;
                &lt;td&gt;1.6b&lt;/td&gt;
                &lt;td&gt;32.0%&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;StableCode&lt;/td&gt;
                &lt;td&gt;3b&lt;/td&gt;
                &lt;td&gt;20.2%&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;ReplitCode v1&lt;/td&gt;
                &lt;td&gt;3b&lt;/td&gt;
                &lt;td&gt;21.9%&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;CodeGen2.5-multi&lt;/td&gt;
                &lt;td&gt;7b&lt;/td&gt;
                &lt;td&gt;28.4%&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;CodeLlama&lt;/td&gt;
                &lt;td&gt;7b&lt;/td&gt;
                &lt;td&gt;33.5%&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;StarCoder&lt;/td&gt;
                &lt;td&gt;15b&lt;/td&gt;
                &lt;td&gt;33.6%&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;&lt;/div&gt;


&lt;p&gt;The base model was trained on our own set of code with permissive licenses only and open text datasets (the text to code ratio was 50:50). In total, we trained our base model on 1.2T tokens of code on our cluster.&lt;/p&gt;

&lt;p&gt;The model was then fine-tuned with open code instruction-following datasets filtered for quality and a synthetic dataset based on &lt;a href="https://huggingface.co/datasets/bigcode/the-stack-dedup" rel="noopener noreferrer"&gt;The Stack dedup v1.1&lt;/a&gt; to improve FIM and boosting the base model performance. &lt;/p&gt;

&lt;p&gt;You can read more about the architecture decisions that we made in the &lt;a href="https://refact.ai/blog/2023/applying-recent-innovations-to-train-model/" rel="noopener noreferrer"&gt;blog post&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;We aim for the model to be accessible to everyone, we're releasing the model for commercial use under BigScience OpenRAIL-M license and making the weight available on &lt;a href="https://huggingface.co/smallcloudai/Refact-1_6B-fim" rel="noopener noreferrer"&gt;HuggingFace&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;While the trend recently was for the model sizes to get bigger, we wanted to lower barriers to entry and make it a versatile tool for developers with varying hardware setups. With the smaller size, running the model is much faster and affordable than ever: the model can be served on most of all modern GPUs requiring just 3Gb RAM and works great for real-time code completion tasks.&lt;/p&gt;

&lt;p&gt;Refact LLM can be easily integrated into existing developers workflows with &lt;a href="https://github.com/smallcloudai/refact/" rel="noopener noreferrer"&gt;an open-source docker container&lt;/a&gt; and &lt;a href="https://marketplace.visualstudio.com/items?itemName=smallcloud.codify" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; and &lt;a href="https://plugins.jetbrains.com/plugin/20647-codify" rel="noopener noreferrer"&gt;JetBrains&lt;/a&gt; plugins. With Refact's intuitive user interface, developers can utilize the model easily for a variety of coding tasks. Finetune is available in the self-hosting (docker) and Enterprise versions, making suggestions more relevant for your private codebase.&lt;/p&gt;

&lt;p&gt;
  &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Fintroducing-refact-code-llm%2Fpalindrome.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Fintroducing-refact-code-llm%2Fpalindrome.gif"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Refact 1.6B LLM is the third model in the family of our code models, with &lt;a href="https://huggingface.co/smallcloudai/codify_3b_multi" rel="noopener noreferrer"&gt;CodeContrast 3b&lt;/a&gt; and &lt;a href="https://huggingface.co/smallcloudai/codify_medium_multi" rel="noopener noreferrer"&gt;CodeContrast 0.3b&lt;/a&gt; released previously. We aim to continue with our research and future updates to improve the LLM's performance and capabilities. We would love to get community contributions and feedback to enhance the model further. For any questions and ideas, please visit our &lt;a href="https://smallcloud.ai/discord" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>githubcopilot</category>
      <category>programming</category>
    </item>
    <item>
      <title>How To Train a Code Model Using Recent AI Innovations</title>
      <dc:creator>Refact AI</dc:creator>
      <pubDate>Fri, 11 Aug 2023 13:51:20 +0000</pubDate>
      <link>https://forem.com/refact/applying-all-recent-innovations-to-train-a-code-model-4hj5</link>
      <guid>https://forem.com/refact/applying-all-recent-innovations-to-train-a-code-model-4hj5</guid>
      <description>&lt;p&gt;ML is changing fast!&lt;/p&gt;

&lt;p&gt;Recently Meta has &lt;a href="https://research.facebook.com/publications/llama-open-and-efficient-foundation-language-models/" rel="noopener noreferrer"&gt;released LLaMA&lt;/a&gt; model that surprised many people - it packed a lot of magic in a small size. The 12b version was comparable with OpenAI's GPT-3 largest 175B model in quality.&lt;/p&gt;

&lt;p&gt;MosaicML released the &lt;a href="https://www.mosaicml.com/blog/mpt-7b" rel="noopener noreferrer"&gt;MPT-7B&lt;/a&gt; model, which has a context of 60k tokens, thanks to the ALiBi position encoding.&lt;/p&gt;

&lt;p&gt;BigCode released the &lt;a href="https://huggingface.co/blog/starcoder" rel="noopener noreferrer"&gt;StarCoder&lt;/a&gt; model that hits 30.4% on HumanEval pass@1, and they also released a code dataset cleaned of personally identifiable information, called &lt;a href="https://huggingface.co/datasets/bigcode/the-stack" rel="noopener noreferrer"&gt;The Stack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Replit recently released the &lt;a href="https://huggingface.co/replit/replit-code-v1-3b" rel="noopener noreferrer"&gt;replit-code-v1-3b&lt;/a&gt; model trained on code that follows some LLaMA innovations and it shows great metrics, but it has no fill-in-the-middle capability, no diffs, and it has seen no data other than code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We plan to make the model publicly available.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  LLaMA Innovations
&lt;/h2&gt;

&lt;p&gt;The number one thing about LLaMA is that it was trained for 1T tokens (and larger models for 1.4T tokens). But that alone is not enough, the transformer architecture and hyperparameters must be right to continue training for that long.&lt;/p&gt;

&lt;p&gt;Architecture: LLaMA doesn't have the bias terms in self-attention and in MLP - that probably allows weight decay to work better. Self-attention runs independently from MLP, not sequentially - this makes calculations a bit faster because they don't have to wait for each other. LLaMA also uses RMSNorm instead of LayerNorm, but that shouldn't be important.&lt;/p&gt;

&lt;p&gt;Hyperparameters: the most interesting is the batch size of 4M tokens. Early in training, many tokens are surprising for the model, and it gets interesting updates. But to run for longer, each batch needs to have diverse data that is not yet predictable, that's why it should be so big.&lt;/p&gt;

&lt;p&gt;Figure 1: LLaMA loss and metrics get monotonically better for 1T tokens and beyond.&lt;/p&gt;

&lt;p&gt;
  &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage7.png"&gt;&lt;/a&gt;
  &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage1.png"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  ALiBi Position Encoding
&lt;/h2&gt;

&lt;p&gt;Transformers traditionally had absolute position encoding, which means each position in the context of 2048 or so tokens has its own trainable vector. It's horrible, of course, because the same tokens moved left or right will produce different activations! But some still use it, notably the StarCoder model.&lt;/p&gt;

&lt;p&gt;There are three widely used solutions to this:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Relative Attention, introduced in the Transformer XL paper (with a not-very-clear explanation)&lt;/li&gt;
    &lt;li&gt;[Rotary Embeddings](https://arxiv.org/abs/2104.09864) (LLaMA uses this one)&lt;/li&gt;
    &lt;li&gt;[ALiBi](https://arxiv.org/abs/2108.12409v2)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Relative Attention has a big disadvantage: it adds trainable parameters. That means the initialization must be right, gradients must be right. We tried wavelets some time ago instead of trainable parameters and it worked just as well, proving there's no need for trainable parameters here, really.&lt;/p&gt;

&lt;p&gt;Both Rotary Embeddings and ALiBi are great, but ALiBi has an additional advantage - extendable context size, compared to what was used in pretrain. Not immediately in our experience, but after a bit of fine-tuning - still a big advantage.&lt;/p&gt;

&lt;p&gt;But let's directly compare the latter two on a short 15e9 token run:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage9.png" alt="ALiBi"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;img src="https://refact.ai/images/blog/recent-innovations/image5.png"&amp;gt;
    &amp;lt;span&amp;gt;ALiBi&amp;lt;/span&amp;gt;


    &amp;lt;img src="https://refact.ai/images/blog/recent-innovations/image2.png"&amp;gt;
    &amp;lt;span&amp;gt;Rotary&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;So ALiBi even works better for our setup!&lt;/p&gt;

&lt;h2&gt;
  
  
  Early Dropout
&lt;/h2&gt;

&lt;p&gt;Researchers at Meta proposed using &lt;a href="https://arxiv.org/abs/2303.01500" rel="noopener noreferrer"&gt;dropout in early training&lt;/a&gt; to improve underfitting (not overfitting). The way it works is this: put dropout layers at many places in the transformer, gradually turn down the drop rate from 10..15% to zero at the first 20% of the training run.&lt;/p&gt;

&lt;p&gt;According to the paper, it can give a couple of percent on metrics for free, on the test set. Trying this using the same short training run we've got:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage3.png" alt="Early Dropout"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The red run with early dropout has a clear advantage on the training loss (never mind the little drop).&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Query Attention
&lt;/h2&gt;

&lt;p&gt;One of the ways to have a large context size with small memory usage is Multi-Query Attention, used at scale in PaLM models. A short explanation is this: in &lt;strong&gt;Multi-Head&lt;/strong&gt; Attention a self-attention layer produces K, V and Q (keys, values and queries) for each head. But in &lt;strong&gt;Multi-Query&lt;/strong&gt; Attention keys and values are produced just once (not for each head), only the queries are different for each attention head. Look at 2204.02311 for a detailed explanation. &lt;/p&gt;

&lt;p&gt;This allows for a smaller KV cache while sampling and improved inference speed.&lt;/p&gt;

&lt;p&gt;It was recently used in the StarCoder models, where it helps to handle a big context size of 8192.&lt;/p&gt;

&lt;h2&gt;
  
  
  LiON
&lt;/h2&gt;

&lt;p&gt;Another recent development is &lt;a href="https://arxiv.org/abs/2302.06675" rel="noopener noreferrer"&gt;LiON&lt;/a&gt;, an optimizer that makes a bold claim - that it can replace Adam. Adam ruled the world of deep models since its introduction in 2014, nearly a decade!&lt;/p&gt;

&lt;p&gt;Various people are trying LiON on their projects, with varying degrees of success. A good starting point to look around is the &lt;a href="https://github.com/lucidrains/lion-pytorch" rel="noopener noreferrer"&gt;lion-pytorch&lt;/a&gt; on github from Phil Wang aka lucidrains (thank you man!).&lt;/p&gt;

&lt;p&gt;The main problem is the hyperparameters, which are well established for Adam, but it's still a bit of guesswork for LiON. There are three: betas, weight decay, learning rate. We took β1=0.95, β2=0.98 without checking, and tested LR and WD:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LR: gray is Adam with lr=20e-5, others are LiONs from 2e-5 to 5e-5 (the best).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fblog%2Frecent-innovations%2Fimage4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;WD: a higher weight decay (green wd=0.8) is slightly worse in the middle (within error bars?) for this short run but it's just as good at the end, compared to wd=0.6 and wd=0.4. &lt;/p&gt;

&lt;p&gt;We took lr=5e-5 (four times lower than the Adam learning rate) and wd=0.8 (eight times higher than in Adam).&lt;/p&gt;

&lt;p&gt;By the way, the low effect of weight decay on the final result is consistent with the LiON paper: they changed WD from 0.5 to 2.0 to a very little effect on final performance, especially with a higher learning rate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Data
&lt;/h2&gt;

&lt;p&gt;We use Red Pajama as a text dataset, Stack Dedup 1.2 for plain code, and our own internal dataset for diffs.&lt;/p&gt;

&lt;p&gt;We use fill-in-the-middle training almost exactly as in 2207.14255 (but we limit the "middle" part size to 4k chars)&lt;/p&gt;

&lt;h2&gt;
  
  
  Hyperparameters
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;Optimizer&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;LiON β1=0.95, β2=0.98&lt;/b&gt;&lt;/td&gt;
    &lt;td&gt;Batch size&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;2M tokens&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;LR&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;5e-5&lt;/b&gt;&lt;/td&gt;
    &lt;td&gt;Context size&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;4096&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;LR schedule&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;linear to zero with warmup&lt;/b&gt;&lt;/td&gt;
    &lt;td&gt;Dropout&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;p=0.1&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Weight Decay&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;0.8&lt;/b&gt;&lt;/td&gt;
    &lt;td&gt;Dropout schedule&lt;/td&gt;
    &lt;td&gt;&lt;b&gt;to zero at 20% of training&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The model is called "202305-refact2b-mqa-lion", it has 1.6b parameters, we will release the weights for everyone to check out!&lt;/p&gt;

</description>
      <category>llm</category>
      <category>ai</category>
      <category>llama</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Introducing Refact: Open-source alternative to Github Copilot</title>
      <dc:creator>Refact AI</dc:creator>
      <pubDate>Wed, 19 Apr 2023 19:16:19 +0000</pubDate>
      <link>https://forem.com/refact/a-self-hosted-alternative-to-github-copilot-for-vs-code-and-jetbrains-47hg</link>
      <guid>https://forem.com/refact/a-self-hosted-alternative-to-github-copilot-for-vs-code-and-jetbrains-47hg</guid>
      <description>&lt;p&gt;We've just launched Refact.ai, the AI coding assistant that combines code autocompletion, refactoring, and chat inside your favorite IDE.&lt;/p&gt;

&lt;p&gt;You can download our plugin for &lt;a href="https://plugins.jetbrains.com/plugin/20647-codify" rel="noopener noreferrer"&gt;JetBrains&lt;/a&gt; or &lt;a href="https://marketplace.visualstudio.com/items?itemName=smallcloud.codify" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;. It's currently free for everyone while we're in the technical preview, we plan to introduce more pricing tiers soon. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Refact?
&lt;/h2&gt;

&lt;p&gt;We believe next-gen developer assistant tool can benefit greatly from the use of different AI models working in harmony, that's why we decided to power Refact with a combination of models.&lt;/p&gt;

&lt;p&gt;Our proprietary fast and smart AI completion model is state-of-the-art in size and latency. For each language group, we have fine-tuned a specific model to provide speed and accuracy. They are hosted in our data center, ensuring performance and precision for quick boilerplate and basic code refactoring. Plus, by hosting them ourselves, we can ensure the highest level of security and reliability for our users.&lt;/p&gt;

&lt;p&gt;On top of that, we use the powerful GPT-3.5-Turbo and GPT-4 models which make it possible to chat with it using natural language and apply code improvement and explaining functions like “Find/Fix Bugs”, and "Explain Complex Code".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fscheme.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frefact.ai%2Fimages%2Fscheme.svg" alt="Refact.ai scheme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Refact allows you to restrict access to particular files or projects, ensuring that your private code or confidential files are protected. And we don't collect datasets on the server side.&lt;br&gt;
If you have NVIDIA GPU you can self-host our model using our &lt;a href="https://refact.ai/docker/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; or contact us for an on-prem enterprise version.&lt;/p&gt;

&lt;p&gt;Refact offers a wholesome developer experience by making multiple functions available inside one IDE. &lt;/p&gt;

&lt;h2&gt;
  
  
  Autocomplete
&lt;/h2&gt;

&lt;p&gt;At the core of Refact is our autocomplete feature that works with 20+ programming languages, including Python, Javascript, Java, Go, Rust, C++, Ruby, and more. When you type some code, the model automatically generates the suggestion by looking for context up and down.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI Toolbox
&lt;/h2&gt;

&lt;p&gt;To improve your existing code quickly and easily, Refact AI Toolbox allows you to simply highlight the area you want to improve and use one of the functions to find and fix bugs, make code more readable, add console logs, or explain complex code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrated AI Chat
&lt;/h2&gt;

&lt;p&gt;Finally, you can use natural language prompts in the AI Chat to refine, explain, and generate new code, as well as provide hints on API usage and documentation links. Your code is part of the context of the conversation automatically and it also gets pasted back directly into the IDE.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Started
&lt;/h2&gt;

&lt;p&gt;To get started, simply download Refact.ai on &lt;a href="https://plugins.jetbrains.com/plugin/20647-codify" rel="noopener noreferrer"&gt;JetBrains&lt;/a&gt; or &lt;a href="https://marketplace.visualstudio.com/items?itemName=smallcloud.codify" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; for free. We're currently in a technical preview, but we're working hard to introduce different pricing tiers and would love to hear your feedback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Join our &lt;a href="https://www.smallcloud.ai/discord" rel="noopener noreferrer"&gt;Discord community&lt;/a&gt; to help shape the future of independent AI coding assistants.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>code</category>
      <category>vscode</category>
      <category>jetbrains</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
