<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tom Gou on Medium]]></title>
        <description><![CDATA[Stories by Tom Gou on Medium]]></description>
        <link>https://medium.com/@liltom.eth?source=rss-f7d80237ef29------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*riGobgjLoNH4jgwzIWHGCA.jpeg</url>
            <title>Stories by Tom Gou on Medium</title>
            <link>https://medium.com/@liltom.eth?source=rss-f7d80237ef29------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 10:18:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@liltom.eth/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Techniques behind OpenAI Sora]]></title>
            <link>https://medium.com/@liltom.eth/techniques-behind-openai-sora-f1cd3acf9b3e?source=rss-f7d80237ef29------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1cd3acf9b3e</guid>
            <category><![CDATA[sora]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Tom Gou]]></dc:creator>
            <pubDate>Mon, 19 Feb 2024 09:09:27 GMT</pubDate>
            <atom:updated>2024-02-21T08:31:40.716Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8j2e-KNoGZ3S-A7RLCByg.png" /></figure><p>Sora = Video DiT = [VAE Encoder + ViT + Conditional Diffusion+ DiT Block + VAE decoder]</p><h3>What is Sora?</h3><p>Sora is an AI model that can create realistic and imaginative scenes from text instructions.</p><p>You can check it out at <a href="https://openai.com/sora">https://openai.com/sora</a>.</p><p>It is a state-of-the-art (SOTA) text-to-video model that can generate high-quality, high-fidelity 1-minute videos with different aspect ratios and resolutions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*HKpjed9tTSYXQQbehqeZdg.png" /></figure><h3>Techniques behind Sora</h3><p>OpenAI has also released the technical <a href="https://openai.com/research/video-generation-models-as-world-simulators">report</a>. Some take on Sora.</p><ul><li>Sora is built on DiT diffusion transformer model (Scalable Diffusion Models with Transformers, ICCV 2023)</li><li>Sora has visual patches for generative models (ViT patches for video inputs)</li><li>“Video compressor network”, (Visual Encoder and Decoder, probably VAE)</li><li>Scaling transformers (Sora has proven that diffusion transformers scale effectively)</li><li>1920x1080p videos for training (no cropping)</li><li>re-captioning (OpenAI DALL·E 3) and text extending (OpenAI GPT)</li></ul><h4>Sora Possible Architecture</h4><p>Sora = Video DiT = [VAE Encoder + ViT + Conditional Diffusion+ DiT Block + VAE decoder]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8j2e-KNoGZ3S-A7RLCByg.png" /></figure><p>From OpenAI Sora technical <a href="https://openai.com/research/video-generation-models-as-world-simulators">report</a> and Saining Xie’s <a href="https://x.com/sainingxie/status/1758433676105310543?s=20">twitter</a>, we can tell that Sora is based on Diffusion Transformer Models. It leverages a lot from DiT, ViT, and Diffusion Models without many fancy pieces of stuff.</p><p>Before Sora, it was unclear if long-form consistency could be achieved. Usually, these kinds of models can only generate 256*256 videos of several seconds. “We take inspiration from large language models which acquire generalist capabilities by training on internet-scale data.” Sora has shown this long-form consistency could be achieved with end-to-end training on maybe internet-scale data.</p><h4>From Diffusion Model to DIT and Sora</h4><p>Diffusion transformer (DiT) model is introduced from (Scalable Diffusion Models with Transformers, ICCV 2023).</p><p>Basiclly, Diffusion transformer (DiT) is a Diffusion model with Transformer (instead of U-Net).</p><p>A typical Diffusion Model looks like below (High-Resolution Image Synthesis with Latent Diffusion Models):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/0*Zt57tz-htCQglSsH" /></figure><p>Diffusion models are generative models that generate high-resolution images of varying quality. They work by gradually adding Gaussian noise to the original data in the <strong>forward diffusion process</strong>(adding noise) and then learning to remove the noise in the <strong>reverse diffusion process</strong>(denoising).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zs6W4NI2J9z2QvIorfunsA.jpeg" /></figure><p>Diffusion transformer (DiT) model is based on Diffusion model and replace the U-Net with Transformers. To process visual data, Diffusion transformer (DiT) also leverages the classic Vision Transformer (<em>ViT</em>) and rearranges the 2D visual features into a sequence. Graph below shows how Patch + Position Embedding works in Vision Transformer (<em>ViT</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/0*MXsgGn91AgflndzY" /></figure><p>Like Diffusion transformer (DiT), Sora also use Patch + Position Embedding to rearrange the 2D visual features into a sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmWjoRXOrEqeeMH8xvJxbw.png" /></figure><p>Based on these techniques from Diffusion transformer (DiT), Diffusion Model and Vision Transformer (*ViT*), we can figure out the Sora Architecture like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*shYG8cstPU6ICZGg" /></figure><p>Sora = Video DiT = [VAE Encoder + ViT + Conditional Diffusion+ DiT Block + VAE decoder]</p><p>Sora has no big difference with DiT, but Sora has proven its long-term spacetime consistency by scaling up its model and training size.</p><p>Also, there are still a lot of unknown tech details behind Sora.</p><h3>Other Techiques</h3><h4>Scaling Transformers</h4><p>“Importantly, Sora is a diffusion <em>transformer</em>. <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-26">26</a> Transformers have demonstrated remarkable scaling properties across a variety of domains, including language modeling, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-13">13</a>, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-14">14</a> computer vision, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-15">15</a>, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-16">16</a>, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-17">17</a>, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-18">18</a> and image generation. <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-27">27</a>, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-28">28</a>, <a href="https://openai.com/research/video-generation-models-as-world-simulators#fn-29">29</a>”</p><p>Graph below shows base compute(left), 4x compute(middle), 32x compute(right). We can tell 32x compute has much better results than base compute.</p><p>Sora has proven that diffusion transformers scale effectively as video models as well. When training compute increases, sample quality improves markedly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-Vc4zdTNv9CRpBMG" /></figure><h4>Native-size training data like 1920x1080p videos</h4><p>“We compare Sora against a version of our model that crops all training videos to be square, which is common practice when training generative models. The model trained on square crops (left) sometimes generates videos where the subject is only partially in view. In comparison, videos from Sora (right) have improved framing.”</p><p>For video models, training on native-size data could improve framing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/0*S1bV_RGB3TyttGOr" /></figure><h4>DALLE3 re-captioning</h4><p>“We apply the re-captioning technique introduced in DALL·E 3 to videos. We first train a highly descriptive captioner model and then use it to produce text captions for all videos in our training set. We find that training on highly descriptive video captions improves text fidelity as well as the overall quality of videos.”</p><p>“Similar to DALL·E 3, we also leverage GPT to turn short user prompts into longer detailed captions that are sent to the video model. This enables Sora to generate high-quality videos that accurately follow user prompts.”</p><h4>What is Visual Patches?</h4><p>“Whereas LLMs have text tokens, Sora has visual <em>patches</em>. Patches have previously been shown to be an effective representation for models of visual data.”</p><p>Visual Patches here are visual features generated from the Visual Encoder (VAE) and then patched and positioned into a sequence of patches (tokens).</p><p>“Given a compressed input video, we extract a sequence of spacetime patches which act as transformer tokens.”</p><p>Visual Patches are also spacetime patches since the input visual data are videos.</p><h4>Visual Encoder and Decoder</h4><p>OpenAI calls them “Video compressor network”. “We train a network that reduces the dimensionality of visual data.”</p><p>From Saining Xie’s <a href="https://x.com/sainingxie/status/1758433676105310543?s=20">twitter</a>, looks like “Video compressor network” is just a VAE but trained on raw video data.</p><h3>Takeaways</h3><p>Sora = Video DiT = [VAE Encoder + ViT + Conditional Diffusion+ DiT Block + VAE decoder]</p><p>Sora has proven the scalability of Diffusion transformer (DiT) like models. Based on these model setups, similar text2video results are achievable with the scaling GPUs and training data.</p><p>However, to achieve the long-term spacetime consistency shown by Sora, there are still a lot unknown techniques.</p><p>Sora is the ChatGPT moment in the video generation industry, I believe similar models will be released soon from one of the top companies (Meta, Google, Amazon). There might also be a LLAMA moment happening in this industry if they open-source it.</p><p>BTW, when Sora came out, the video generation architecture from Pika and Runaway would definitely be out-of-date. They must be hurrying switching their architecture to Sora-like models. For me, LLAMA moment on video generation would be more exciting.</p><h3>Reference</h3><p><a href="https://openai.com/research/video-generation-models-as-world-simulators">https://openai.com/research/video-generation-models-as-world-simulators</a></p><p><a href="https://kailashahirwar.medium.com/a-very-short-introduction-to-diffusion-models-a84235e4e9ae">A Very Short Introduction to Diffusion Models</a></p><p><a href="https://www.linkedin.com/pulse/how-sora-works-detailed-explanation-speculation-ethan-he-dh0oc/?utm_source=share&amp;utm_medium=member_ios&amp;utm_campaign=share_via">How Sora works — detailed explanation (speculation)</a></p><p><a href="https://tiancaixinxin.medium.com/nvidia-researcher-view-openais-sora-is-amazing-but-not-because-of-the-patches-3da7ce583b75">Nvidia Researcher: OpenAI’s Sora is Amazing, but not because of the Patches</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1cd3acf9b3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenAI DevDay — Recap]]></title>
            <link>https://medium.com/@liltom.eth/openai-devday-recap-1f4a3fdba313?source=rss-f7d80237ef29------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f4a3fdba313</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[gpt-4]]></category>
            <dc:creator><![CDATA[Tom Gou]]></dc:creator>
            <pubDate>Tue, 07 Nov 2023 04:10:36 GMT</pubDate>
            <atom:updated>2023-11-07T04:10:36.991Z</atom:updated>
            <content:encoded><![CDATA[<h3>OpenAI DevDay — Recap</h3><h3>GPTs</h3><p>(iPhone App Store Moment.)</p><ul><li>GPTs are tailored versions of ChatGPT for specific purposes.</li><li>Build with natural language.</li><li>GPT Store launch later Nov.</li><li>Revenue sharing. More information soon.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G3m8KNb1Y5eT32oZ" /></figure><p>Try <a href="https://openai.com/chatgpt#do-more-with-gpts">examples</a></p><h4>Code.org</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VgVsuc5uQB4FuBxR.png" /></figure><h4>Canva</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V_IeXWR5DzDEQcq-.png" /></figure><h4>Zapier</h4><p>automation on calendar, message…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZOJhSou8-G5izXcp.png" /></figure><h3>Assistants API</h3><p>Our first step towards helping developers build agent-like experiences.</p><p>A key change introduced by this API is <strong>persistent and infinitely long threads</strong>, which allow developers to hand off thread state management to OpenAI and work around context window constraints. With the Assistants API, you simply add each new message to an existing thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/0*19AN2BvgJuRpuZXf.png" /></figure><p>Capabilities:</p><p>Retrieval</p><ul><li>augments the assistant with knowledge from outside our models</li></ul><p>Code Interpreter</p><ul><li>writes and runs Python code in a sandboxed execution environment, and can generate graphs and charts, and process files with diverse data and formatting.</li></ul><p>Function calling</p><ul><li>enables assistants to invoke functions you define and incorporate the function response in their messages.</li></ul><h3>New Modalities in the API</h3><h4>DALL·E 3</h4><ul><li>programmatically generate images</li></ul><h4>GPT-4 Turbo with vision</h4><ul><li>GPT-4 Turbo can accept images as inputs in the Chat Completions API, enabling use cases such as generating captions, analyzing real world images in detail, and reading documents with figures.</li></ul><h4>Text-to-speech (TTS)</h4><ul><li>Our new TTS model offers six preset voices to choose from and two model variants, tts-1 and tts-1-hd. tts is optimized for real-time use cases and tts-1-hd is optimized for quality.</li></ul><h4>Whisper v3</h4><ul><li>We are releasing <a href="https://github.com/openai/whisper">Whisper large-v3,</a> the next version of our open source automatic speech recognition model (ASR) which features improved performance across languages. We also plan to support Whisper v3 in our API in the near future.</li></ul><h3>GPT-4 Turbo</h3><h4>Context length</h4><ul><li>128k context length (more than 300 pages of text in a single prompt)</li></ul><h4>More Control</h4><p>json mode to call APIs</p><ul><li>ensures the model will respond with valid JSON</li></ul><p>Function calling</p><ul><li>call multiple functions in a single message (parallel function calling)</li><li>improving function calling accuracy</li></ul><p>Reproducible outputs</p><ul><li>pass seed parameter</li></ul><p>View log probabilities in the API (in the next few weeks)</p><ul><li>useful for building features such as autocomplete in a search</li></ul><h4>Better Knowledge</h4><ul><li>April 2023</li></ul><h4>Customization</h4><ul><li>GPT-4 fine-tuning experimental access</li><li>Custom models</li></ul><h4>Copyright Shield</h4><ul><li>We do not train on your data from the API, or ChatGPT Enterprise, ever.</li></ul><h4>Price</h4><ul><li>GPT-4 Turbo at a <a href="https://openai.com/pricing#gpt-4-turbo">3x cheaper</a> price for input tokens and a 2x cheaper price for output tokens compared to GPT-4.</li></ul><h4>Speed</h4><ul><li>soon you will find turbo a lot faster</li></ul><h3>Reference</h3><p><a href="https://devday.openai.com/">https://devday.openai.com/</a></p><p><a href="https://openai.com/blog/new-models-and-developer-products-announced-at-devday">https://openai.com/blog/new-models-and-developer-products-announced-at-devday</a></p><p><a href="https://openai.com/blog/introducing-gpts">https://openai.com/blog/introducing-gpts</a></p><p><a href="https://zapier.com/blog/gpt-assistant/">https://zapier.com/blog/gpt-assistant/</a></p><p><a href="https://www.youtube.com/watch?v=U9mJuUkhUzk">https://www.youtube.com/watch?v=U9mJuUkhUzk</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f4a3fdba313" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy LLaVA-1.5 on Amazon SageMaker]]></title>
            <link>https://medium.com/@liltom.eth/deploy-llava-1-5-on-amazon-sagemaker-168b2efd2489?source=rss-f7d80237ef29------2</link>
            <guid isPermaLink="false">https://medium.com/p/168b2efd2489</guid>
            <category><![CDATA[sagemaker]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[multimodal]]></category>
            <dc:creator><![CDATA[Tom Gou]]></dc:creator>
            <pubDate>Fri, 20 Oct 2023 01:12:34 GMT</pubDate>
            <atom:updated>2023-10-20T01:12:34.671Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/976/0*6iAY3-ftKULT5RqH" /></figure><h3>What is LLaVA-1.5?</h3><ul><li>LLaVA (Large Language-and-Vision Assistant) is a model that can be trained end-to-end by combining a Vision encoder and LLM.</li><li>LLaVA-1.5 achieves SoTA on 11 benchmarks.</li></ul><p>Paper or resources for more information: <a href="https://llava-vl.github.io/">https://llava-vl.github.io/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/0*VXhVDfXWfdgzX5SF" /></figure><h3>Deploy Huggingface models to Amazon SageMaker</h3><p>Amazon SageMaker is a popular platform for running AI models, and models on huggingface deploy <a href="https://github.com/huggingface/transformers">Hugging Face Transformers</a> using <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/whatis.html">Amazon SageMaker</a> and the <a href="https://sagemaker.readthedocs.io/en/stable/">Amazon SageMaker Python SDK</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*XAz96Nhzmr1zfUds" /></figure><p>For models integrated in <a href="https://github.com/huggingface/transformers">Hugging Face Transformers</a>, they can easily deployed to SageMaker from Hub:</p><pre>from sagemaker.huggingface.model import HuggingFaceModel<br>hub = {<br>  &#39;HF_MODEL_ID&#39;:&#39;distilbert-base-uncased-distilled-squad&#39;, # model_id from hf.co/models<br>  &#39;HF_TASK&#39;:&#39;question-answering&#39;                           # NLP task you want to use for predictions<br>}<br># create Hugging Face Model Class<br>huggingface_model = HuggingFaceModel(<br>   env=hub,                                                # configuration for loading model from Hub<br>   role=role,                                              # IAM role with permissions to create an endpoint<br>   transformers_version=&quot;4.26&quot;,                             # Transformers version used<br>   pytorch_version=&quot;1.13&quot;,                                  # PyTorch version used<br>   py_version=&#39;py39&#39;,                                      # Python version used<br>)<br><br># deploy model to SageMaker Inference<br>predictor = huggingface_model.deploy(<br>   initial_instance_count=1,<br>   instance_type=&quot;ml.m5.xlarge&quot;<br>)</pre><p>Usually, we just provide the HF_MODEL_ID and HF_TASK and the Hugging Face DLC takes care of the rest.</p><p>However, for new models like LLaVA-1.5 is still not integrated in <a href="https://github.com/huggingface/transformers">Hugging Face Transformers</a> right now, thus we need to creat a model.tar.gz containing inference.py and model weights to deploy it as a customized model. Amazon SageMaker allows us to customize the inference script by providing a inference.py file.</p><h3>Download Model with Inference Code</h3><p><a href="https://huggingface.co/anymodality/llava-v1.5-7b">anymodality/llava-v1.5–7b</a> forked from original <a href="https://huggingface.co/liuhaotian/llava-v1.5-7b">liuhaotian/llava-v1.5–7b</a> model and added code/inference.py and code/requirements.txt to provide customize inference script and environment.</p><p>You can git clone to download the repo:</p><pre># Make sure you have git-lfs installed (https://git-lfs.com) <br>git lfs install <br>git clone https://huggingface.co/anymodality/llava-v1.5-7b <br># if you want to clone without large files - just their pointers <br># prepend your git clone with the following env var: <br>GIT_LFS_SKIP_SMUDGE=1</pre><p>Or use huggingface_hub SDK:</p><pre>from huggingface_hub import snapshot_download<br>HF_MODEL_ID=&quot;anymodality/llava-v1.5-7b&quot;<br><br>model_dir = Path(HF_MODEL_ID.split(&quot;/&quot;)[-1])<br>model_dir.mkdir(exist_ok=True)<br># Download model from Hugging Face into model_dir<br>snapshot_download(HF_MODEL_ID, local_dir=str(model_tar_dir), local_dir_use_symlinks=False)</pre><p>The <a href="https://huggingface.co/anymodality/llava-v1.5-7b">anymodality/llava-v1.5–7b</a> repo contains model weights, inference code, inference environment and deploy script:</p><pre>llava-v1.5-7b/<br>|- config.json<br>|- pytorch_model-00001-of-00002.bin<br>|- tokenizer.json<br>|- code/inference.py<br>|- code/requirements.txt<br>|- deploy_llava.ipynb</pre><p>You can follow deploy_llava.ipynb for next steps.</p><h3>Create SageMaker model.tar.gz artifact</h3><p>Following deploy_llava.ipynb , bundle llava model weights and code into a model.tar.gz:</p><pre># Create SageMaker model.tar.gz artifact<br>!tar -cf model.tar.gz --use-compress-program=pigz *p</pre><p>model.tar.gz will contains all files of the repo.</p><p>After we created the model.tar.gz archive we can upload it to Amazon S3. We will use the sagemaker SDK to upload the model to our sagemaker session bucket.</p><pre>from sagemaker.s3 import S3Uploader<br><br># upload model.tar.gz to s3<br>s3_model_uri = S3Uploader.upload(local_path=&quot;./model.tar.gz&quot;, desired_s3_uri=f&quot;s3://{sess.default_bucket()}/llava-v1.5-7b&quot;)<br><br>print(f&quot;model uploaded to: {s3_model_uri}&quot;)</pre><h3>Deploy the model to Amazon SageMaker</h3><p>Following deploy_llava.ipynb , we can deploy our model to Amazon SageMaker. We will use HuggingfaceModel to create our real-time inference endpoint.</p><pre>from sagemaker.huggingface.model import HuggingFaceModel<br><br># create Hugging Face Model Class<br>huggingface_model = HuggingFaceModel(<br>   model_data=s3_model_uri,      # path to your model and script<br>   role=role,                    # iam role with permissions to create an Endpoint<br>   transformers_version=&quot;4.28.1&quot;,  # transformers version used<br>   pytorch_version=&quot;2.0.0&quot;,       # pytorch version used<br>   py_version=&#39;py310&#39;,            # python version used<br>   model_server_workers=1<br>)<br><br># deploy the endpoint endpoint<br>predictor = huggingface_model.deploy(<br>    initial_instance_count=1,<br>    instance_type=&quot;ml.g5.xlarge&quot;,<br>    # container_startup_health_check_timeout=600, # increase timeout for large models<br>    # model_data_download_timeout=600, # increase timeout for large models<br>)</pre><h3>Run inference</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/0*BBLsCHs-gLmVZZrV" /></figure><p>The .deploy() returns an HuggingFacePredictor object which can be used to request inference using the .predict() method. Our endpoint expects a json with at least image and question key.</p><pre>data = {<br>    &quot;image&quot; : &#39;https://raw.githubusercontent.com/haotian-liu/LLaVA/main/images/llava_logo.png&#39;, <br>    &quot;question&quot; : &quot;Describe the image and color details.&quot;,<br>    # &quot;max_new_tokens&quot; : 1024,<br>    # &quot;temperature&quot; : 0.2,<br>    # &quot;stop_str&quot; : &quot;###&quot;<br>}<br><br># request<br>output = predictor.predict(data)<br>print(output)</pre><p>To run inference with llava special token:</p><pre>from llava.conversation import conv_templates, SeparatorStyle<br>from llava.constants import (<br>DEFAULT_IMAGE_TOKEN,<br>DEFAULT_IM_START_TOKEN,<br>DEFAULT_IM_END_TOKEN,<br>)<br>def get_prompt(raw_prompt):<br>    conv_mode = &quot;llava_v1&quot;<br>    conv = conv_templates[conv_mode].copy()<br>    roles = conv.roles<br>    inp = f&quot;{roles[0]}: {raw_prompt}&quot;<br>    inp = (<br>        DEFAULT_IM_START_TOKEN + DEFAULT_IMAGE_TOKEN + DEFAULT_IM_END_TOKEN + &quot;\n&quot; + inp<br>    )<br>    conv.append_message(conv.roles[0], inp)<br>    conv.append_message(conv.roles[1], None)<br>    prompt = conv.get_prompt()<br>    stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2<br>    return prompt, stop_str<br><br>raw_prompt = &quot;Describe the image and color details.&quot;<br>prompt, stop_str = get_prompt(raw_prompt)<br>image_path = &quot;https://raw.githubusercontent.com/haotian-liu/LLaVA/main/images/llava_logo.png&quot;<br>data = {&quot;image&quot; : image_path, &quot;question&quot; : prompt, &quot;stop_str&quot; : stop_str}<br>output = predictor.predict(data)<br>print(output)</pre><p>get_prompt() function will generate llava prompt with raw_prompt.</p><p>The inference predictor can also be initilized like with your deployed endpoint_name :</p><pre>import sagemaker<br>import boto3<br>sess = sagemaker.Session()<br>try:<br>    role = sagemaker.get_execution_role()<br>except ValueError:<br>    iam = boto3.client(&#39;iam&#39;)<br>    # setup your own rolename in sagemaker<br>    role = iam.get_role(RoleName=&#39;AmazonSageMaker-ExecutionRole-20231008T201275&#39;)[&#39;Role&#39;][&#39;Arn&#39;]<br><br>from sagemaker.huggingface.model import HuggingFacePredictor<br># initial the endpoint predictor<br>predictor2 = HuggingFacePredictor(<br>    endpoint_name=&quot;huggingface-pytorch-inference-2023-10-19-05-57-37-847&quot;,<br>    sagemaker_session=sess<br>)</pre><p>Or use <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker-runtime/client/invoke_endpoint.html#invoke-endpoint">SageMakerRuntime</a> to setup endpoint invoking client.</p><p>More details in deploy_llava.ipynb.</p><h3>Delete model and endpoint</h3><p>To clean up, we can delete the model and endpoint by delete_endpoint() or using sagemaker console.</p><pre>predictor.delete_model() <br>predictor.delete_endpoint()</pre><h3>Repo</h3><p><a href="https://huggingface.co/anymodality/llava-v1.5-7b">anymodality/llava-v1.5–7b</a> forked from original <a href="https://huggingface.co/liuhaotian/llava-v1.5-7b">liuhaotian/llava-v1.5–7b</a> model and added code/inference.py and code/requirements.txt to provide customize inference script and environment.</p><p><a href="https://huggingface.co/anymodality/llava-v1.5-13b">anymodality/llava-v1.5–13b</a> is the 13b version forked from <a href="https://huggingface.co/liuhaotian/llava-v1.5-13b">liuhaotian/llava-v1.5–13b</a>.</p><p><em>Originally published at </em><a href="https://huggingface.co/anymodality/llava-v1.5-7b">https://huggingface.co/anymodality/llava-v1.5-7b</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=168b2efd2489" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run Code Llama locally on Your Macbook]]></title>
            <link>https://medium.com/@liltom.eth/run-code-llama-locally-on-your-macbook-b386f96d293c?source=rss-f7d80237ef29------2</link>
            <guid isPermaLink="false">https://medium.com/p/b386f96d293c</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[code-llama]]></category>
            <category><![CDATA[github-copilot]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[llama-2]]></category>
            <dc:creator><![CDATA[Tom Gou]]></dc:creator>
            <pubDate>Fri, 01 Sep 2023 03:06:21 GMT</pubDate>
            <atom:updated>2023-09-01T19:06:13.830Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Code Llama?</h3><ul><li>Code Llama is an AI model built on top of <a href="https://about.fb.com/news/2023/07/llama-2/">Llama 2</a>, fine-tuned for generating and discussing code.</li><li>It’s free for research and commercial use.</li></ul><p>Code Llama aids in code completion and debugging endeavors, seamlessly accommodating popular languages like Python, C++, Java, PHP, Typescript (Javascript), C#, and Bash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bnM3lqUOexs3ybrD" /></figure><p>In this section, I will go through the code to explain each step in detail.</p><h3>Run Code Llama on MacBook Walkthrough</h3><h3>Getting Started</h3><p>Code Llama’s <a href="https://huggingface.co/codellama">Model weights</a> are available on Huggingface.</p><ul><li>Base model <strong>Code Llama</strong> and extend model <strong>Code Llama — Python</strong> are not fine-tuned to follow instructions. They should be prompted so that the expected answer is the natural continuation of the prompt. That means these two models focus on code filling and code completion</li><li>extend model <strong>Code Llama — Instruct</strong> trained with “natural language instruction” inputs paired with anticipated outputs. This strategic methodology enhances the model’s capacity to grasp human expectations in prompts. That means instruct models can be used in a chatbot-like app.</li></ul><h3>Install</h3><p><a href="https://pypi.org/project/llama2-wrapper/">llama2-wrapper</a> is the package wrapping multiple llama2 backends (transformers, gptq, llama.cpp) and provides <a href="https://github.com/liltom-eth/llama2-webui">llama2-webui</a> to run chatbot and code playground for Code Llama.</p><p>Install can easy with pip:</p><pre>pip install llama2-wrapper</pre><p>Clone the repo:</p><pre>git clone https://github.com/liltom-eth/llama2-webui.git</pre><h3>Run Code Completion / Filling</h3><p>Download <strong>Code Llama</strong> or <strong>Code Llama — Python</strong> (llama.cpp version for MacBook)</p><pre>python -m llama2_wrapper.download --repo_id TheBloke/CodeLlama-7B-GGML --filename codellama-7b.ggmlv3.Q4_0.bin --save_dir ./models</pre><p>Run Web UI:</p><pre>cd llama2-webui <br>python code_completion.py --model_path ./models/codellama-7b.ggmlv3.Q4_0.bin</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o7dJtB3RNNUcKEb-" /></figure><h3>Run Code Chat</h3><p>Download <strong>Code Llama — Instruct</strong> (llama.cpp version for MacBook)</p><pre>python -m llama2_wrapper.download --repo_id TheBloke/CodeLlama-7B-Instruct-GGML --filename codellama-7b-instruct.ggmlv3.Q4_0.bin --save_dir ./models</pre><p>Run Web UI:</p><pre>cd llama2-webui <br>python app.py --model_path ./models/codellama-7b.ggmlv3.Q4_0.bin</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vIcujCLNfj0sKTLM" /></figure><h3>Code Llama Benchmarks</h3><p>Code Llama outperforms open-source coding LLMs. It’s two times better than the 70B Llama 2 model. It also outperforms GPT 3.5 and is on-par with GPT-4 with only 34B params. That’s quite an achievement!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c-QD_SVDnPSFwAzW" /></figure><p><em>The code can be found at </em><a href="https://github.com/liltom-eth/llama2-webui">https://github.com/liltom-eth/llama2-webui</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b386f96d293c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>