{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "name": "ti_deepseek_r1_moe_mla_kv_cache_simulator.ipynb" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# DeepSeek R1 MoE (671B / 37B Active) & Multi-Head Latent Attention (MLA) KV-Cache Simulator\n", "**Companion Benchmark Notebook by [The Infosiast](https://theinfosiast.com/deepseek-r1-architecture-deployment-guide/)**\n", "\n", "- Interactive Browser Calculator: [DeepSeek R1 Architecture & Deployment Guide](https://theinfosiast.com/deepseek-r1-architecture-deployment-guide/#ti-moe-calculator)\n", "- Local Ollama Sizing Matrix: [Run DeepSeek R1 Locally with Ollama](https://theinfosiast.com/run-deepseek-r1-locally-ollama-hardware-requirements/#ti-deepseek-sizer)\n" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "def simulate_deepseek_r1_memory(context_tokens=32768, bits_per_weight=4.5):\n", " total_params_b = 671.0\n", " active_params_b = 37.0\n", " weights_gb = (total_params_b * bits_per_weight / 8.0) * 1.08\n", " # Standard GQA KV-cache vs DeepSeek MLA compressed latent KV-cache (d_c = 512, 61 layers)\n", " std_gqa_kv_gb = (context_tokens * 61 * 2 * 8 * 128 * 2) / (1024**3)\n", " mla_kv_gb = (context_tokens * 61 * (512 + 64) * 2) / (1024**3)\n", " return {\n", " 'context_tokens': context_tokens,\n", " 'weights_gb': round(weights_gb, 2),\n", " 'active_params_b': active_params_b,\n", " 'standard_gqa_kv_gb': round(std_gqa_kv_gb, 2),\n", " 'deepseek_mla_kv_gb': round(mla_kv_gb, 2),\n", " 'kv_cache_reduction_pct': round((1 - mla_kv_gb / std_gqa_kv_gb) * 100, 1),\n", " }\n", "\n", "for ctx in [8192, 32768, 65536, 131072]:\n", " print(simulate_deepseek_r1_memory(ctx))\n" ] } ] }