# Granite Code — IBM Open Source AI Coding Models > IBM's open-source code LLMs from 3B to 34B parameters. Trained on 116 programming languages with Apache 2.0 license. Top performer on code benchmarks. ## Install Paste the prompt below into your AI tool: ## Quick Use ```bash # Via Ollama ollama pull granite-code:8b ollama run granite-code:8b "Write a Python function to merge two sorted lists" # Via Hugging Face pip install transformers torch ``` ```python from transformers import AutoModelForCausalLM, AutoTokenizer model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-8b-code-instruct") tokenizer = AutoTokenizer.from_pretrained("ibm-granite/granite-8b-code-instruct") inputs = tokenizer("def fibonacci(n):", return_tensors="pt") outputs = model.generate(**inputs, max_new_tokens=200) print(tokenizer.decode(outputs[0])) ``` ## What is Granite Code? Granite Code is IBM's family of open-source code language models, ranging from 3B to 34B parameters. Trained on 116 programming languages with a deduplicated dataset of 3-4 trillion tokens, these models deliver strong performance on code generation, completion, and explanation tasks. **Answer-Ready**: Granite Code is IBM's open-source code LLM family (3B to 34B parameters) trained on 116 programming languages. Apache 2.0 licensed, it ranks among top open-source code models on HumanEval and MBPP benchmarks. **Best for**: Teams needing a self-hosted, commercially-licensed code AI. **Works with**: Ollama, vLLM, Hugging Face, any OpenAI-compatible server. **Setup time**: Under 5 minutes with Ollama. ## Model Variants | Model | Parameters | Use Case | |-------|-----------|----------| | granite-3b-code | 3B | Edge devices, fast completion | | granite-8b-code | 8B | General coding, best speed/quality balance | | granite-20b-code | 20B | Complex code generation | | granite-34b-code | 34B | Maximum quality, multi-file tasks | Each has `-base` (completion) and `-instruct` (chat/instruction) variants. ## Key Strengths ### 1. 116 Languages Python, JavaScript, TypeScript, Java, Go, Rust, C/C++, SQL, and 108 more. ### 2. Apache 2.0 License Fully open for commercial use — no restrictions, no fees, no CLA. ### 3. Benchmark Performance Granite 34B-code competes with Code Llama 34B and StarCoder2 15B on: - HumanEval: Python code generation - MBPP: Multi-language programming - DS-1000: Data science tasks ### 4. Fill-in-the-Middle Supports FIM for IDE-style code completion: ``` def add(a, b): return result ``` ### 5. Long Context Supports up to 128K tokens for large codebase understanding. ## Deployment Options ```bash # Ollama (easiest) ollama serve ollama pull granite-code:8b # vLLM (production) pip install vllm vllm serve ibm-granite/granite-8b-code-instruct # Continue.dev (IDE integration) # Add to ~/.continue/config.json ``` ## FAQ **Q: How does it compare to Code Llama?** A: Granite 34B matches or exceeds Code Llama 34B on most benchmarks, with a more permissive Apache 2.0 license (vs Llama's custom license). **Q: Can I use it commercially?** A: Yes, Apache 2.0 — no restrictions on commercial use. **Q: Best model size for coding?** A: 8B offers the best speed/quality tradeoff. Use 34B for complex multi-file tasks. ## Source & Thanks > Created by [IBM Research](https://github.com/ibm-granite). Licensed under Apache 2.0. > > [ibm-granite/granite-code-models](https://github.com/ibm-granite/granite-code-models) — 2k+ stars ## 快速使用 ```bash ollama pull granite-code:8b ollama run granite-code:8b "写一个归并排序" ``` 一行命令下载并运行 IBM 开源代码模型。 ## 什么是 Granite Code? Granite Code 是 IBM 的开源代码语言模型系列,参数量从 3B 到 34B,训练数据覆盖 116 种编程语言。 **一句话总结**:IBM 开源代码 LLM 家族(3B-34B),116 种语言,Apache 2.0 许可证,开源代码模型基准测试前列。 **适合人群**:需要自托管、可商用代码 AI 的团队。**支持**:Ollama、vLLM、Hugging Face。 ## 核心亮点 ### 1. 116 种编程语言 Python、JavaScript、Go、Rust 等全覆盖。 ### 2. Apache 2.0 许可 完全开放商用,无限制。 ### 3. 多尺寸选择 3B(边缘设备)→ 8B(通用)→ 34B(最高质量)。 ### 4. 长上下文 支持 128K token,理解大型代码库。 ## 常见问题 **Q: 和 Code Llama 比较?** A: Granite 34B 基准测试持平或超越 Code Llama 34B,且许可证更宽松(Apache 2.0)。 **Q: 可以商用吗?** A: 可以,Apache 2.0 无限制。 ## 来源与致谢 > [ibm-granite/granite-code-models](https://github.com/ibm-granite/granite-code-models) — Apache 2.0 --- Source: https://tokrepo.com/en/workflows/727e129c-8063-4c7f-b02f-b43ba209e9a0 Author: Prompt Lab