{"id":11367,"date":"2024-12-23T07:14:54","date_gmt":"2024-12-23T07:14:54","guid":{"rendered":"https:\/\/metaschool.so\/articles\/?p=11367"},"modified":"2024-12-23T07:16:32","modified_gmt":"2024-12-23T07:16:32","slug":"qwen2-5-coder","status":"publish","type":"post","link":"https:\/\/metaschool.so\/articles\/qwen2-5-coder\/","title":{"rendered":"Qwen2.5-Coder \u2014 A Comprehensive Guide"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_56_1 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/metaschool.so\/articles\/qwen2-5-coder\/#What_is_the_Qwen25-Coder\" title=\"What is the Qwen2.5-Coder?\">What is the Qwen2.5-Coder?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/metaschool.so\/articles\/qwen2-5-coder\/#Key_Features_of_Qwen25-Coder\" title=\"Key Features of Qwen2.5-Coder\">Key Features of Qwen2.5-Coder<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/metaschool.so\/articles\/qwen2-5-coder\/#Code_Implementation\" title=\"Code Implementation\">Code Implementation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/metaschool.so\/articles\/qwen2-5-coder\/#FAQs\" title=\"FAQs\">FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>The world of software development is evolving rapidly, and AI is at the forefront of this transformation. Developers today are leveraging advanced tools to automate tedious tasks, streamline workflows, and create innovative solutions. Among these tools, code-specific large language models (LLMs) like the Qwen Coder are proving to be game-changers. They\u2019re not just simplifying coding processes but also opening doors to new possibilities in automation and innovation.<\/p>\n\n\n\n<p>In this article, we explore how you can harness the power of AI to enhance productivity, reduce errors, and create impactful tools tailored to your needs. Whether you&#8217;re an experienced developer or just getting started, this guide will inspire you to reimagine how you build and optimize your projects using AI-driven solutions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_Qwen25-Coder\"><\/span>What is the Qwen2.5-Coder?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/qwenlm.github.io\/blog\/qwen2.5-coder-family\/\" target=\"_blank\" rel=\"noopener\">Qwen2.5-Coder<\/a> is a specialized large language model (LLM) developed by Alibaba Cloud&#8217;s Qwen team, tailored specifically for coding tasks. It excels in code generation, reasoning, and fixing across more than 40 programming languages, making it a versatile tool for developers. The model is available in various sizes, including 0.5B, 1.5B, 3B, 7B, 14B, and 32B parameters, to accommodate different computational resources and requirements.<\/p>\n\n\n\n<p>The 32B variant, in particular, has demonstrated performance comparable to proprietary models like GPT-4, achieving high scores on benchmarks such as McEval and MdEval. This makes Qwen2.5-Coder a powerful open-source alternative for developers seeking advanced code-related capabilities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Key_Features_of_Qwen25-Coder\"><\/span>Key Features of Qwen2.5-Coder<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Qwen2.5-Coder introduces cutting-edge capabilities that redefine the coding experience for developers across various domains.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/ollama.com\/library\/qwen2.5-coder\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1638\" height=\"769\" src=\"https:\/\/metaschool.so\/articles\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-23-115912.png\" alt=\"\" class=\"wp-image-11406\" srcset=\"https:\/\/metaschool.so\/articles\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-23-115912.png 1638w, https:\/\/metaschool.so\/articles\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-23-115912-300x141.png 300w, https:\/\/metaschool.so\/articles\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-23-115912-1024x481.png 1024w, https:\/\/metaschool.so\/articles\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-23-115912-768x361.png 768w, https:\/\/metaschool.so\/articles\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-23-115912-1536x721.png 1536w\" sizes=\"auto, (max-width: 1638px) 100vw, 1638px\" \/><\/a><figcaption class=\"wp-element-caption\">Qwen2.5-Coder Model Scores on different Benchmarks<\/figcaption><\/figure>\n<\/div>\n\n\n<p>Below is an updated overview of its standout features:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Code Generation<\/strong><\/h4>\n\n\n\n<p>Qwen2.5-Coder excels at automatically generating code snippets based on natural language prompts. This streamlines the development process, saving time and enabling rapid prototyping for applications ranging from web development to advanced machine learning pipelines.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Code Completion<\/strong><\/h4>\n\n\n\n<p>The model enhances productivity by completing partial code, and intelligently suggesting solutions that reduce errors and improve coding efficiency. Developers can quickly fill in missing sections of their code, allowing for seamless workflows.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Code Review Assistance<\/strong><\/h4>\n\n\n\n<p>With its robust review capabilities, Qwen2.5-Coder detects syntax errors, enforces coding standards, and provides optimization suggestions. This feature ensures that code remains clean, maintainable, and performant.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Advanced Debugging<\/strong><\/h4>\n\n\n\n<p>Qwen2.5-Coder&#8217;s debugging functionality identifies and resolves complex coding issues efficiently. By leveraging its advanced reasoning capabilities, developers can quickly pinpoint errors and apply effective fixes, significantly reducing debugging time.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. Support for Multiple Programming Languages<\/strong><\/h4>\n\n\n\n<p>This model is proficient across 40+ programming languages, including Haskell, Racket, Python, JavaScript, and more. Its multi-language capabilities ensure it meets the needs of developers working in diverse coding environments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. Multi-Language Code Repair<\/strong><\/h4>\n\n\n\n<p>The model stands out for its exceptional code repair skills in multiple languages. It simplifies understanding and modifying unfamiliar languages, reducing the learning curve and enhancing accessibility for developers worldwide.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7. Long-Context Support<\/strong><\/h4>\n\n\n\n<p>With the ability to handle up to 128K tokens, Qwen2.5-Coder effectively manages extensive codebases and documents. This long-context support is invaluable for analyzing large projects, documentation, or code-heavy repositories.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>8. Diverse Model Sizes<\/strong><\/h4>\n\n\n\n<p>Qwen2.5-Coder offers six distinct model sizes: 0.5B, 1.5B, 3B, 7B, 14B, and 32B parameters. These options cater to various computational resources and requirements, making the model adaptable for individual developers, small teams, and large organizations alike.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>9. State-of-the-Art Performance<\/strong><\/h4>\n\n\n\n<p>Qwen2.5-Coder-32B-Instruct has achieved state-of-the-art performance across popular benchmarks, including EvalPlus, LiveCodeBench, and BigCodeBench. It matches the capabilities of GPT-4o, making it one of the most powerful open-source coding models available.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>10. Human Preference Alignment<\/strong><\/h4>\n\n\n\n<p>The model aligns with human preferences through an internal benchmark, Code Arena. This ensures that Qwen2.5-Coder not only generates functional code but also aligns with best practices and developer expectations.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>11. Practical Use Cases<\/strong><\/h4>\n\n\n\n<p>Designed for real-world applications, the Qwen2.5-Coder is suitable for tasks such as code generation, repair, reasoning, and development assistance. It is a versatile tool that supports a wide range of development scenarios, from quick prototypes to large-scale enterprise projects.<\/p>\n\n\n\n<p>These features collectively position Qwen2.5-Coder as a top-tier tool for developers, enabling innovation, efficiency, and reliability in modern software development. Whether you&#8217;re debugging, generating, or reviewing code, Qwen2.5-Coder ensures an optimized and seamless coding experience.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Models<\/strong><\/th><th><strong>Params<\/strong><\/th><th><strong>Layers<\/strong><\/th><th><strong>Context Length<\/strong><\/th><th><strong>Token Limits<\/strong><\/th><th><strong>Ideal Use Cases<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Qwen2.5-Coder-0.5B<\/td><td>0.49B<\/td><td>24<\/td><td>32K<\/td><td>~65K Tokens<\/td><td>Lightweight tasks, quick prototype testing.<\/td><\/tr><tr><td>Qwen2.5-Coder-1.5B<\/td><td>1.54B<\/td><td>28<\/td><td>32K<\/td><td>~100K Tokens<\/td><td>Small-scale applications, code autocompletion.<\/td><\/tr><tr><td>Qwen2.5-Coder-3B<\/td><td>3.09B<\/td><td>36<\/td><td>32K<\/td><td>~150K Tokens<\/td><td>Medium-complexity tasks, lightweight inference.<\/td><\/tr><tr><td>Qwen2.5-Coder-7B<\/td><td>7.61B<\/td><td>28<\/td><td>128K<\/td><td>~250K Tokens<\/td><td>Complex code generation, multi-language support.<\/td><\/tr><tr><td>Qwen2.5-Coder-14B<\/td><td>14.7B<\/td><td>48<\/td><td>128K<\/td><td>~500K Tokens<\/td><td>Advanced applications, large-scale model tuning.<\/td><\/tr><tr><td>Qwen2.5-Coder-32B<\/td><td>32.5B<\/td><td>64<\/td><td>128K<\/td><td>~1M Tokens<\/td><td>Enterprise-level applications, long-context tasks.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>To help you choose the right model for your needs, we&#8217;ve compiled a comprehensive comparison of the Qwen2.5-Coder series. Each model is designed to cater to specific requirements, balancing parameter size, context length, and token limits to ensure optimal performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Code_Implementation\"><\/span>Code Implementation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this section, we&#8217;ll explore how to implement code completion using the Qwen2.5-Coder model. We will discuss setting up the environment, loading the model, and executing a code completion task.<\/p>\n\n\n\n<p>If you need more information or context at any step, please refer to Qwen&#8217;s <a href=\"https:\/\/qwen.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"noopener\">official documentation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Environment Setup<\/strong><\/h3>\n\n\n\n<p>Ensure you have installed Python 3.9 or higher. You&#8217;ll also need the <code>transformers<\/code> library version 4.37.0 or above, as it includes the necessary integrations for Qwen2.5 models. <\/p>\n\n\n\n<p>In the directory you are working, create a <code>requirements.txt<\/code> file and copy this into the file:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"torch\ntransformers==4.39.1\naccelerate\nsafetensors\nvllm\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">torch<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">transformers==4.39.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">accelerate<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">safetensors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">vllm<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now you can easily install the required packages using a <code>requirements.txt<\/code> file:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pip install -r requirements.txt\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">pip<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">install<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">-r<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">requirements.txt<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Loading the Model and Tokenizer<\/h3>\n\n\n\n<p>We&#8217;ll use the <code>AutoModelForCausalLM<\/code> and <code>AutoTokenizer<\/code> classes from the <code>transformers<\/code> library to load the Qwen2.5-Coder model. For this example, we&#8217;ll utilize the 7B parameter model, which offers a balance between performance and resource requirements.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"from transformers import AutoModelForCausalLM, AutoTokenizer\n\nmodel_name = &quot;Qwen\/Qwen2.5-Coder-7B&quot;\n\n# Load the tokenizer\ntokenizer = AutoTokenizer.from_pretrained(model_name)\n\n# Load the model with device mapping for efficient computation\nmodel = AutoModelForCausalLM.from_pretrained(\n    model_name,\n    torch_dtype=&quot;auto&quot;,\n    device_map=&quot;auto&quot;\n).eval()\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">from<\/span><span style=\"color: #D4D4D4\"> transformers <\/span><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> AutoModelForCausalLM, AutoTokenizer<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">model_name = <\/span><span style=\"color: #CE9178\">&quot;Qwen\/Qwen2.5-Coder-7B&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Load the tokenizer<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">tokenizer = AutoTokenizer.from_pretrained(model_name)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Load the model with device mapping for efficient computation<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">model = AutoModelForCausalLM.from_pretrained(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    model_name,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">torch_dtype<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;auto&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">device_map<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;auto&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">).eval()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Preparing the Input Prompt<\/h3>\n\n\n\n<p>Let&#8217;s consider a scenario where we want the model to generate a Python function that calculates the factorial of a number. We&#8217;ll provide a prompt to guide the model:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"prompt = &quot;# Function to calculate factorial of a number\\n&quot;\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">prompt = <\/span><span style=\"color: #CE9178\">&quot;# Function to calculate factorial of a number<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tokenizing the Input<\/h3>\n\n\n\n<p>We need to convert the input prompt into tokens that the model can process.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Tokenize the input prompt\ninput_tokens = tokenizer(prompt, return_tensors=&quot;pt&quot;).to(model.device)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># Tokenize the input prompt<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">input_tokens = tokenizer(prompt, <\/span><span style=\"color: #9CDCFE\">return_tensors<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;pt&quot;<\/span><span style=\"color: #D4D4D4\">).to(model.device)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Generating the Code Completion<\/h3>\n\n\n\n<p>With the input tokens prepared, we can now generate the code completion. We&#8217;ll set a limit on the maximum number of new tokens to generate to control the length of the output.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Generate code completion\noutput_tokens = model.generate(\n    input_tokens.input_ids,\n    max_new_tokens=100,  # Adjust as needed\n    do_sample=False  # Deterministic output\n)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># Generate code completion<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">output_tokens = model.generate(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    input_tokens.input_ids,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">max_new_tokens<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #B5CEA8\">100<\/span><span style=\"color: #D4D4D4\">,  <\/span><span style=\"color: #6A9955\"># Adjust as needed<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">do_sample<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">False<\/span><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># Deterministic output<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Decoding and Displaying the Output<\/h3>\n\n\n\n<p>Finally, we&#8217;ll decode the generated tokens back into human-readable text and display the complete function.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Decode the generated tokens to text\ngenerated_code = tokenizer.decode(output_tokens[0], skip_special_tokens=True)\n\n# Print the complete function\nprint(generated_code)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># Decode the generated tokens to text<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">generated_code = tokenizer.decode(output_tokens[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">], <\/span><span style=\"color: #9CDCFE\">skip_special_tokens<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">True<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Print the complete function<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(generated_code)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Complete Code<\/h3>\n\n\n\n<p>Combining all the steps, here&#8217;s the complete code:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"from transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Specify the model name\nmodel_name = &quot;Qwen\/Qwen2.5-Coder-7B&quot;\n\n# Load the tokenizer and model\ntokenizer = AutoTokenizer.from_pretrained(model_name)\nmodel = AutoModelForCausalLM.from_pretrained(\n    model_name,\n    torch_dtype=&quot;auto&quot;,\n    device_map=&quot;auto&quot;\n).eval()\n\n# Define the input prompt\nprompt = &quot;# Function to calculate factorial of a number\\n&quot;\n\n# Tokenize the input prompt\ninput_tokens = tokenizer(prompt, return_tensors=&quot;pt&quot;).to(model.device)\n\n# Generate code completion\noutput_tokens = model.generate(\n    input_tokens.input_ids,\n    max_new_tokens=100,\n    do_sample=False\n)\n\n# Decode the generated tokens to text\ngenerated_code = tokenizer.decode(output_tokens[0], skip_special_tokens=True)\n\n# Print the complete function\nprint(generated_code)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">from<\/span><span style=\"color: #D4D4D4\"> transformers <\/span><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> AutoModelForCausalLM, AutoTokenizer<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Specify the model name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">model_name = <\/span><span style=\"color: #CE9178\">&quot;Qwen\/Qwen2.5-Coder-7B&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Load the tokenizer and model<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">tokenizer = AutoTokenizer.from_pretrained(model_name)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">model = AutoModelForCausalLM.from_pretrained(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    model_name,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">torch_dtype<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;auto&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">device_map<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;auto&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">).eval()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Define the input prompt<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">prompt = <\/span><span style=\"color: #CE9178\">&quot;# Function to calculate factorial of a number<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Tokenize the input prompt<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">input_tokens = tokenizer(prompt, <\/span><span style=\"color: #9CDCFE\">return_tensors<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;pt&quot;<\/span><span style=\"color: #D4D4D4\">).to(model.device)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Generate code completion<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">output_tokens = model.generate(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    input_tokens.input_ids,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">max_new_tokens<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #B5CEA8\">100<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">do_sample<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">False<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Decode the generated tokens to text<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">generated_code = tokenizer.decode(output_tokens[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">], <\/span><span style=\"color: #9CDCFE\">skip_special_tokens<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">True<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># Print the complete function<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(generated_code)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Expected Output<\/strong><\/p>\n\n\n\n<p>When you run the above code, you can expect an output similar to:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Function to calculate factorial of a number\ndef factorial(n):\n    if n == 0:\n        return 1\n    else:\n        return n * factorial(n - 1)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># Function to calculate factorial of a number<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">factorial<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">n<\/span><span style=\"color: #D4D4D4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> n == <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> n * factorial(n - <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This demonstrates how Qwen2.5-Coder can assist in generating functional code snippets based on simple prompts, streamlining the development process.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Note:<\/strong> Ensure that your system has the necessary computational resources to handle the model, especially for larger variants like the 7B model. Adjust the <code>max_new_tokens<\/code> parameter as needed to control the length of the generated code.<\/p>\n\n\n\n<p>For more detailed information and advanced usage, refer to the <a href=\"https:\/\/github.com\/QwenLM\/Qwen2.5-Coder\" target=\"_blank\" rel=\"noopener\">Qwen2.5-Coder GitHub repository<\/a>.<\/p>\n<\/blockquote>\n\n\n\n<p><strong>Related Reading:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/metaschool.so\/articles\/blackbox-ai\">Guide to Blackbox AI \u2013 Solve Your Coding Challenges With AI<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/metaschool.so\/articles\/starcoder\">StarCoder: LLM for Code \u2014 A Comprehensive Guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/metaschool.so\/articles\/build-a-code-review-assistant-using-ai\">How to Build a Code Review Assistant Using AI \u2014 A Comprehensive Guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/metaschool.so\/articles\/ai-software-development\">AI in Software Development<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1734527076543\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is Qwen 2.5 Coder?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Qwen 2.5 Coder is an advanced AI-powered tool developed by Alibaba Cloud&#8217;s Qwen team. It assists developers by providing code suggestions, automating repetitive tasks, and enhancing overall coding efficiency. <a href=\"https:\/\/qwenlm.github.io\/blog\/qwen2.5-coder-family\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1734527090205\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How does Qwen 2.5 Coder improve coding productivity?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Qwen 2.5 Coder leverages AI to suggest optimized code snippets, identify errors in real-time, and offer smart code completions, helping developers write code faster and with fewer mistakes. <a href=\"https:\/\/qwenlm.github.io\/blog\/qwen2.5-coder-family\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1734527103237\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Is Qwen 2.5 Coder suitable for beginners?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, Qwen 2.5 Coder is user-friendly and can assist beginners by offering suggestions and explanations on coding concepts, making it an ideal tool for learners. <a href=\"https:\/\/www.autonomous.ai\/ourblog\/qwen-2-5?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1734527118532\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How accurate are the code suggestions provided by Qwen 2.5 Coder?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The code suggestions provided by Qwen 2.5 Coder are highly accurate, thanks to its AI model trained on large codebases. However, it&#8217;s always recommended to review the suggestions for your specific use case. <a href=\"https:\/\/qwenlm.github.io\/blog\/qwen2.5-coder-family\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":19,"featured_media":11373,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[344],"tags":[],"class_list":["post-11367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence"],"_links":{"self":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/11367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/comments?post=11367"}],"version-history":[{"count":10,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/11367\/revisions"}],"predecessor-version":[{"id":11411,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/11367\/revisions\/11411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media\/11373"}],"wp:attachment":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media?parent=11367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/categories?post=11367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/tags?post=11367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}