How to Run NVIDIA Dory 4B with llama.cpp: Loop by Loop Guide
In this tutorial, we work with Dory 1.0 4B, a small reasoning model from NVIDIA’s Nemotron Labs whose middle layers form a shared block that can be applied once, twice, three, or four times for every token.
Each extra pass, or loop, spends more computation per token without adding a single parameter, so one checkpoint can run at four different compute budgets with no retraining.We build the llama.cpp branch that NVIDIA’s model card pins, download the 3.
7 GB GGUF, and read the architecture straight from the file to predict what each loop should cost in parameters and cache memory.
We then check those predictions against the running server, measure decode speed at every loop count, test whether the cheaper last-loop cache changes the model’s predictions, and run a paired GSM8K evaluation to see how accuracy, answer length, and time per solved question move as the loops increase.
Copy CodeCopiedUse a different Browserimport os import re import sys import json import time import math import random import signal import shutil import hashlib import platform import statistics import traceback import subprocess import collections import urllib.
request from pathlib import Path RESULTS = {} # step -> one-line result, for the summary table CLAIMS = [] # (step, claim, held) CURRENT = ["1"] def banner(title): print("\n" + "=" 78) print(title) print("=" 78) def section(name): def wrap(fn): def run(a, kw): CURRENT[0] = name.split(".
")[0] banner(name) t0 = time.time() try: out = fn(a, kw) RESULTS[name] = out if isinstance(out, str) else "ok" return out except Exception as e: RESULTS[name] = f"SKIPPED / FAILED -> {type(e).name}: {e}" print(f"\n[!] {name} did not complete: {type(e).name}: {e}") traceback.
printexc(limit=3) return None finally: print(f"\n[{time.time() - t0:.1f} s]") return run return wrap def claim(text, held): CLAIMS.append((CURRENT[0], text, bool(held))) return held banner("1.Build the pinned Dory llama.cpp fork and record the environment") FORK = "https://github.
com/brianchmielNV/llama.cpp.git" FORKCOMMIT = "98a74c97ea09ac72f6ceda1559808fc0a2f447ce" # the commit NVIDIA's model card pins; ggml-org PR #30306 is still a draft GGUFREPO = "nvidia/NVIDIA-Nemotron-Labs-Dory1.
0-4B-GGUF" GGUFREV = "df53755cb8741843af8e019e088819fbef17e29b" GGUFFILE = "NVIDIA-Nemotron-Labs-Dory1.0-4B-Q5KM.gguf" # the card's commands call it dory-q5km.
gguf GGUFSIZE = 3673288864 GGUFSHA256 = "96080be49ffd67b916018b7bdef8c484762576fb52780e10ab98ac4978a660e0" GSM8KREV = "740312add88f781978c0658806c59bc2815b9866" WORK = Path(os.environ.get("DORYWORK") or ("/content/dory" if os.path.isdir("/content") else "dorywork")).resolve() WORK.
mkdir(parents=True, existok=True) (WORK / "logs").mkdir(existok=True) subprocess.run([sys.executable, "-m", "pip", "install", "-q", "gguf==0.19.0", "huggingfacehub", "pandas", "pyarrow"], check=True) SYSTEM = platform.system() GPU = "" if shutil.which("nvidia-smi"): q = subprocess.
run(["nvidia-smi", "--query-gpu=name,memory.total,computecap", "--format=csv,noheader"], captureoutput=True, text=True) GPU = q.stdout.strip().splitlines()[0] if q.returncode == 0 and q.stdout.
strip() else "" BACKEND = "metal" if SYSTEM == "Darwin" else ("cuda" if GPU else "cpu") SRC = WORK / "llama.cpp-dory" SERVERBIN = SRC / "build" / "bin" / "llama-server" freegb = shutil.diskusage(WORK).free / 1e9 print(f"{SYSTEM} {platform.machine()}, Python {platform.pythonversion()}, {os.
cpucount()} CPU cores, " f"backend {BACKEND}{' (' + GPU + ')' if GPU else ''}, {freegb:.1f} GB free disk") if not SERVERBIN.exists(): t0 = time.time() if not (SRC / ".git").exists(): subprocess.run(["git", "init", "-q", str(SRC)], check=True) subprocess.
run(["git", "-C", str(SRC), "remote", "add", "origin", FORK], check=True) subprocess.run(["git", "-C", str(SRC), "fetch", "-q", "--depth", "1", "origin", FORKCOMMIT], check=True) subprocess.
run(["git", "-C", str(SRC), "checkout", "-q", "--detach", "FETCHHEAD"], check=True) flags = ["-DCMAKEBUILDTYPE=Release", "-DLLAMABUILDSERVER=ON", "-DLLAMABUILDTESTS=OFF", "-DLLAMABUILDEXAMPLES=OFF", "-DLLAMABUILDAPP=OFF", "-DLLAMABUILDUI=OFF", "-DLLAMAUSEPREBUILTUI=ON", "-DLLAMAOPENSSL=OFF"] if BACKEND == "metal": # the card's Apple-silicon flags flags += ["-DCMAKEOSXARCHITECTURES=arm64", "-DGGMLMETAL=ON", "-DGGMLMETALEMBEDLIBRARY=ON", "-DGGMLBLAS=ON", "-DGGMLBLASVENDOR=Apple"] elif BACKEND == "cuda": # kernels for this GPU only (a T4 is 7.
5); flash-attention kernels are unused with --flash-attn off cap = GPU.split(",")[-1].strip().replace(".", "") flags += ["-DGGMLCUDA=ON", f"-DCMAKECUDAARCHITECTURES={cap}", "-DGGMLCUDAFA=OFF", "-DGGMLNATIVE=OFF"] env = dict(os.environ, HFUIVERSION="b11551") with open(WORK / "build.
log", "w") as log: subprocess.run(["cmake", "-S", str(SRC), "-B", str(SRC / "build")] + flags, check=True, env=env, stdout=log, stderr=log) subprocess.run(["cmake", "--build", str(SRC / "build"), "--parallel", str(os.
cpucount()), "--target", "llama-server"], check=True, env=env, stdout=log, stderr=log) print(f"built llama-server in {time.time() - t0:.0f} s") head = subprocess.run(["git", "-C", str(SRC), "rev-parse", "HEAD"], captureoutput=True, text=True).stdout.
strip() assert head == FORKCOMMIT, f"checked out {head}, expected {FORKCOMMIT}" version = subprocess.run([str(SERVERBIN), "--version"], captureoutput=True, text=True) print(f"fork commit {head[:12]}; {(version.stdout + version.stderr).strip().splitlines()[-1]}") RESULTS["1.
Build the pinned Dory llama.cpp fork and record the environment"] = f"fork {head[:12]}, backend {BACKEND}" We build llama-server from the exact commit of the Dory branch that NVIDIA’s model card pins, because Dory support in llama.
cpp is still an open draft pull request and no released binary can load the model.
The cell detects the platform and passes the card’s Metal flags on a Mac, or compiles CUDA kernels for the attached GPU alone on Colab, skipping the flash-attention kernels that the card’s –flash-attn off never uses, which keeps a T4 build manageable.
It then checks that the checked-out commit is the pinned one, so every later number traces to one known version of the code.Copy CodeCopiedUse a different Browser@section("2.
Download the Q5KM GGUF at a pinned revision and check its SHA-256") def downloadstep(): global GGUF from huggingfacehub import hfhubdownload t0 = time.time() GGUF = Path(hfhubdownload(GGUFREPO, GGUFFILE, revision=GGUFREV, localdir=str(WORK))) h = hashlib.
sha256() with open(GGUF, "rb") as f: for block in iter(lambda: f.read(1 << 24), b""): h.update(block) size, digest = GGUF.stat().stsize, h.hexdigest() print(f"{GGUF.name}: {size:,} bytes, sha256 {digest[:16]}...({time.time() - t0:.
0f} s)") assert size == GGUFSIZE and digest == GGUFSHA256, "the file does not match the card's size and checksum" claim("the GGUF matches the size and SHA-256 published on the card", True) return f"{size / 1e9:.
2f} GB, checksum matches the card" downloadstep() The Q5KM GGUF comes from Hugging Face at a fixed repository revision, and we hash it before anything else touches it.The card’s commands refer to the file as dory-q5km.gguf, but the repository names it NVIDIA-Nemotron-Labs-Dory1.0-4B-Q5KM.
gguf, so copying the card’s command verbatim fails; pinning the real name, the size, and the SHA-256 together catches both a wrong file and a corrupted download.The 3.67 GB file matches the card’s published checksum exactly, so every measurement that follows uses the same bytes NVIDIA published.
Copy CodeCopiedUse a different Browser@section("3.Read the architecture from the GGUF: three layer groups and a default of four loops") def architecturestep(): global META, GROUPS, PATTERN import gguf reader = gguf.GGUFReader(str(GGUF)) META = {k: f.contents() for k, f in reader.fields.items() if k.
startswith("dory.")} for k in ("dory.blockcount", "dory.inputlayercount", "dory.recurrentlayercount", "dory.outputlayercount
Related
相關文章
4.7 萬條假名人內容被清:網信辦給 AI 換臉帶貨踩剎車
通報點名的四類典型,幾乎都奔著"變現"去:一是未經授權用 AI 仿名人肖像聲音、甚至盜用其家屬照片帶貨引流;二是盜肖像配 AI 特效編造"患病"等謠言誤導公眾;三是以第一人稱冒充名人發表觀點、情感話術誘人關注;四是生成名人跳低俗舞蹈、親密互動的畫面吸粉牟利,涉及微信、抖音、小紅書、B 站、快手等多平臺。
申通快遞和千問辦公達成戰略合作,推動物流服務智能化升級
今日消息,申通快遞與千問辦公正式達成戰略合作。雙方將圍繞快遞核心場景打造 AI 辦公體系,以Agent能力支撐申通快遞全國網點的增長戰略落地,推動AI從總部管理向末端網點規模化輸出,加速物流服務智能化升級。申通快遞總裁韓永彥與千問辦公CEO陳宇森等共同見證簽約。 圖示 申通快遞和千問辦公戰略合作簽約現場 申通快遞作為中國頭部快遞企業,擁有覆蓋全國的轉運、網點及末端派送網絡,聚焦快遞主業,為超過40個行業提供定製化解決方案,搭建一體化倉配供應鏈服務體系,網絡覆蓋廣、區域佈局縱深、網點多級協同運營,沉澱了深厚的快遞場景經驗與運營積澱。 面對鏈路長、協同要求高的物流場景,申通快遞對高效率、可落地、安全可控的企業級 AI 生產力工具存在深層次需求。千問辦公本次和申通快遞合作,將把 Agent 套件能力與申通快遞的行業經驗深度融合,共同打造快遞行業 Agent 規模化落地標杆,沉澱出可供整個物流行業持續複用的數字資產。 此前,千問辦公已在申通快遞安全管理、人力資源、行政運營等場景率先落地。以安全管理為例,過去員工的安全諮詢與預警動態均依賴人工處理;如今依託千問辦公,常見安全問題能由Agent自動響應,預警信息每日定時推送。此外,安全團隊還藉助千問辦公搭建管理後臺,將事件監控、實時臺賬與趨勢分析匯成統一視圖,推動安全管理從“被動響應”轉向“主動管理”。這一變化,也與申通快遞推動網點運營從“經驗驅動”向“數據驅動”轉型的方向一致。 未來,申通快遞將在全國網點推進千問辦公落地,重點提升網點管理與運營效率,並在電商場景共同打造智慧物流,幫助商家增強運營和服務能力,提升消費者購物體驗。 據公開資料,千問辦公是阿里旗下企業級通用Agent產品,是AI辦公賽道增長最快的產品之一,目前行業頭部企業均已接入千問辦公。
Thinking Machines Releases Inkling 2 Small, a 594B MoE With 17B Active
Thinking Machines Lab has released Inkling 2 Small, the first model of its second Inkling generation.The Inkling 2 Small model is a sparse Mixture-of-Experts (MoE) with 594B total and 17B active parameters.
月之暗面放大招!Kimi Hosted Agents 正式發佈
Kimi Hosted Agents 正式發佈發布於AI新閒資訊時間 :Nov 6, 2026閱讀 :1分鐘11月5日,人工智能前沿企業月之暗面(Moonshot AI)官方正式宣佈推出全新的 Kimi Hosted Agents(託管智能體) 服務。
解讀丨王騰創業一年,正把小米模式搬進臥室
手機行業過去的最強“話題製造機”,這次沒聊手機。作者丨陳玘凡編輯丨吳優2026年10月29日,北京嘉瑞文化中心二樓。王騰站在臺上,手裡拿著一枚戒指。這一天,距離他正式離開小米,剛過去一年零五十天。手機行業曾經最會製造話題的市場操盤手之一,這次沒有講手機,而是以今日宜休之名發佈了兩個最"安靜"的產品:一枚智能戒指,一張以床笠形態加裝在床上的溫控系統。但問題是:在智能戒指已經殺成紅海、智能床罩由Eight Sleep佔據先機的賽道里,這兩款售價1799元起的戒指和9999元起的床笠,到底有什麼不一樣?
獨家解讀 | 大疆老兵研發運動硬件,如何一年做出兩款產品?
成立兩年發佈兩款產品,累計融資千萬美元。作者丨陳玘凡 編輯丨吳優侯昊翔、曹曦、張津劍,三位 85 後頂流投資人的名字,出現在同一份股東名單上,本身就是一件值得琢磨的事。侯昊翔,厚雪資本創始合夥人兼總裁,福布斯 2024 創投人 100 榜上榜者,主導過壁仞科技等明星項目;曹曦創辦礪思資本(Monolith),投出了月之暗面、DeepSeek;張津劍與綠洲資本投出過MiniMax、逐際動力。把三位聯繫在一起的,是一家成立僅兩年半的運動科技公司皓翊星辰(LUMISTAR)。01造過 200 萬臺無人機的人,來造網球機皓翊星辰由厚雪資本孵化,日常經營交給專業團隊獨立運轉,核心成員來自大疆、字節、小紅書等公司。公司目前約80人,產研人員超過一半。網球發球機看似只是"一臺會發球的機器",實際是一門重結構的硬件生意。高速發球對機身強度、供球機構的可靠性、整機重量都提出了苛刻要求,任何一塊短板都有可能變成用戶手裡的故障。行業從業者告訴雷峰網·鯨犀,發球機殼體壁厚低於 2mm、被 70-80 公里/小時的球速擊打,很容易損壞,有網球發球機器人產品為追求便攜犧牲了結構強度,曾在體驗活動中被用戶打出的球擊破外殼。(想了解更多網球機器人行業內幕,歡迎添加作者微信 IvarQFC 交流)做網球發球機,需要一個結構能力過硬的研發負責人。皓翊星辰的硬件負責人正是結構工程師出身,擁有多年消費電子經驗。他曾參與研發 Mavic Mini 一代,這是大疆首個銷量破 200 萬臺的產品;還參與Insta360 GO系列拇指相機、雲鯨掃地機等產品。懂硬件的人來做網球機,落在產品上是一連串明確的取捨。公司此前有面向B端測試機,系統複雜且不可靠。團隊覆盤後轉向C端,核心洞察是“物理阻力”的問題。個人用戶買網球機,除去價格,最大的障礙就是把幾十公斤的機器從家搬到球場。誰把機器做得便攜、可靠、好用,誰就能打開C端市場。