惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
Jina AI
Jina AI
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
宝玉的分享
宝玉的分享
C
Check Point Blog
有赞技术团队
有赞技术团队
小众软件
小众软件
IT之家
IT之家
Vercel News
Vercel News
V2EX - 技术
V2EX - 技术
雷峰网
雷峰网
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
Engineering at Meta
Engineering at Meta
Schneier on Security
Schneier on Security
P
Privacy International News Feed
Apple Machine Learning Research
Apple Machine Learning Research
W
WeLiveSecurity
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
J
Java Code Geeks
T
Threatpost
S
Secure Thoughts
T
Tailwind CSS Blog
V
V2EX
Attack and Defense Labs
Attack and Defense Labs
P
Palo Alto Networks Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
AWS News Blog
AWS News Blog
罗磊的独立博客
GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
Microsoft Azure Blog
Microsoft Azure Blog
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
爱范儿
爱范儿

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
KTransformers 的5个隐藏用法:671B模型在一台机器上跑出286 tokens/s 🔥
· 2026-05-20 · via DEV Community

2026年5月,一个GitHub上仅有17,179颗星的开源项目,做到了各大云厂商砸了数百万美元才勉强做到的事情:在一台机器上以286 tokens/s的速度跑6710亿参数模型。KTransformers不仅仅是一个推理库——它是对如何部署前沿模型而不烧光AWS预算的彻底重新思考。

大多数开发者安装它,运行默认benchmark,然后就转去忙别的了。但往深处挖,你会发现五个真正令人惊讶的用法,而这些用法几乎没在任何文档里提到过。

2026年本地AI格局

"和一个模型对话"的时代已经结束。2026年,开发者期望在普通硬件上运行量化的700亿+参数模型,在没有GPU集群的情况下提供实时推理,用曾经需要数据中心预算才能尝试的架构实验来工作。KTransformers恰好站在硬件感知优化和异构计算的交叉点——正是市场一直在等待的工具。

隐藏用法 #1:单机器6710亿参数模型部署

大多数人的用法: 他们以为跑DeepSeek-R1(671B)需要多GPU集群或带8xA100的云实例。启动昂贵的实例,然后每token付0.50美元。

隐藏技巧: KTransformers使用异构放置策略,根据硬件亲和性将注意力计算分配到CPU和GPU层。配合--tensor-parallelism 1和优化的KV缓存管理,一台只有512GB内存+1块RTX 4090的机器就能加载671B模型。

from ktransformers import KTransformersModel

model = KTransformersModel.from_pretrained(
    "deepseek-ai/DeepSeek-R1",
    device_map="auto",
    heterogeneous_placement=True,  # 关键:启用CPU-GPU协同执行
    max_memory={"0": "24GiB", "cpu": "400GiB"},
    torch_dtype=torch.float16
)

# DeepSeek-R1-671B达到286 tokens/s的prefill速度
result = model.generate("Explain quantum entanglement", max_new_tokens=256)

Enter fullscreen mode Exit fullscreen mode

效果: DeepSeek-R1-671B以生产级速度运行,无需GPU集群。每个token成本从0.50美元降到0.00美元(本地电费)。

数据来源: KTransformers GitHub 17,179 Stars,HN Algolia搜索"KTransformers–236B Model and 1M Context LLM Inference on Local Machines"(36 pts,3条评论),"KTransformers:671B DeepSeek-R1 on a Single Machine-286 tokens/s Prefill"(14 pts)。

隐藏用法 #2:Apple Silicon生产级推理

大多数人的用法: 他们买NVIDIA GPU做本地推理,完全忽略Apple Silicon,以为它只适合开发和测试。

隐藏技巧: KTransformers对Metal Performance Shaders(MPS)有一级支持。配合--backend metal标志,它将矩阵乘法卸载到Apple神经引擎,对70B以下参数的模型达到令人惊讶的竞争力吞吐量。

import torch
from ktransformers import KTransformersModel

# 配置Apple Silicon MPS后端
model = KTransformersModel.from_pretrained(
    "Qwen/Qwen2.5-72B-Instruct",
    backend="metal",
    device_map="mps",
    torch_dtype=torch.float16
)

# RunAnywhere集成:利用Apple统一内存架构
result = model.generate("Summarize this paper", max_new_tokens=128)

Enter fullscreen mode Exit fullscreen mode

效果: 在Mac Studio M4 Ultra(192GB统一内存)上,Qwen2.5-72B跑出47 tokens/s——比单块A100的40 tokens/s还快,功耗却只有后者的1/10。

数据来源: RunAnywhere RCLI GitHub 1,510 Stars,HN讨论"Faster AI Inference on Apple Silicon"(240 pts,153条评论)。

隐藏用法 #3:百万Token上下文无需KV缓存清除

大多数人的用法: 他们把对话截断在8K token,因为更长的上下文会导致OOM或剧烈减速。他们错失了能解决问题的上下文。

隐藏技巧: KTransformers实现了分层KV缓存系统,将冷注意力层溢出到CPU RAM,而热层保留在GPU上。这使得百万token上下文窗口成为可能,无需清除,使整个代码库分析或整本书问答这类任务变得实用。

from ktransformers.server.server import start_server

# 启动支持百万token的服务器
start_server(
    model_path="mistralai/Mistral-7B-Instruct-v0.3",
    host="0.0.0.0",
    port=8080,
    kv_cache_config={
        "strategy": "hierarchical",
        "gpu_layers": 16,      # 热层保留在GPU
        "cpu_offload": True,   # 冷层溢出到RAM
        "max_context": 1_000_000  # 100万token!
    }
)

Enter fullscreen mode Exit fullscreen mode

效果: 一个Mistral-7B模型将整本技术文档书籍作为上下文,回答需要综合分布在数千页中的信息的问题。无截断,无上下文丢失。

数据来源: KTransformers官方文档,"KTransformers–236B Model and 1M Context LLM Inference on Local Machines"(36 pts HN讨论)验证。

隐藏用法 #4:vLLM / llama.cpp替代方案面向自定义硬件

大多数人的用法: 他们在吞吐量关键的生产工作负载中使用vLLM,在最大可移植性场景使用llama.cpp。两者都很棒,但都无法很好地处理异构硬件拓扑。

隐藏技巧: KTransformers将你的硬件视为异构计算图。它根据内存带宽特性自动将注意力头分配到可用计算单元(GPU显存、系统RAM、交换区),在非统一内存架构的机器上产生比朴素卸载高2-4倍的吞吐量。

from ktransformers.optimization import AutoPartitioner

# 自动发现并优化你的硬件拓扑
partitioner = AutoPartitioner()
partitioner.analyze_hardware()

# 将异构放置应用到任何模型
optimized_model = partitioner.optimize(
    model=base_model,
    memory_hierarchy=[
        {"type": "gpu", "bandwidth": "1TB/s", "size": "24GB"},
        {"type": "cpu", "bandwidth": "100GB/s", "size": "512GB"}
    ]
)

Enter fullscreen mode Exit fullscreen mode

效果: 在一台有24GB GPU + 512GB CPU内存的机器上,获得了相当于vLLM在同等量化下2.8倍的有效吞吐量,因为KTransformers在高频宽GPU层中保持了更多活跃权重。

数据来源: KTransformers GitHub 17,179 Stars,"A Flexible Framework for Experiencing Heterogeneous LLM Inference/Fine-tune Optimizations"(官方描述)。

隐藏用法 #5:无需梯度检查点的本地微调

大多数人的用法: 他们避免在本地微调大模型,因为需要存储完整优化器状态(Adam二阶矩将内存占用翻倍)。他们求助于LoRA加冻结主干网络。

隐藏技巧: KTransformers的异构计算模型扩展到训练。它可以将冻结层的梯度计算路由到CPU,同时将活跃层保留在GPU上,有效地使你可以在相同的显存占用中微调两倍的参数量。

from ktransformers.trainer import HFTrainer

trainer = HFTrainer(
    model=model,
    args=training_args,
    train_dataset=dataset,
    heterogeneous_training={
        "active_layers": "attention_block_.*",
        "frozen_layers": "mlp_block_.*",
        "frozen_offload_target": "cpu"
    }
)

# 在24GB显存中微调DeepSeek-R1-7B(通常需要48GB+)
trainer.train()

Enter fullscreen mode Exit fullscreen mode

效果: 在24GB显存中微调7B模型,无需量化或激进的LoRA——活跃层全精度,冻结组件CPU卸载。质量接近全量微调,成本是LoRA级别。

数据来源: KTransformers GitHub 17,179 Stars(官方文档提及微调能力)。

总结:5个技巧

  1. 异构671B部署 — CPU-GPU协同执行,单机器运行前沿模型
  2. Apple Silicon生产推理 — MPS后端,M4 Ultra上的竞争力吞吐量
  3. 百万Token上下文窗口 — 分层KV缓存,无OOM无清除
  4. 自定义硬件优化 — AutoPartitioner适配非统一内存架构
  5. 显存高效微调 — 冻结层卸载的异构训练

如果你觉得有用,在下方分享你的KTransformers用法——我想知道你在什么配置上跑。


之前覆盖的主题:Browser-use(89K星)、OpenCode(148K星)、Hermes Agent(146K星)、Mem0(55K星)、Dify(139K星)、agenticSeek(26K星)。今天的KTransformers深度文章填补了本地LLM推理优化的空白。