Xunzhuo commited on
Commit
abd00fe
·
verified ·
1 Parent(s): bc8bf07

d3-flash v3.0.2

Browse files
Files changed (4) hide show
  1. MODEL_MANIFEST.json +8 -8
  2. README.md +1 -1
  3. d3_fast.py +28 -1
  4. d3_runtime.py +41 -2
MODEL_MANIFEST.json CHANGED
@@ -557,8 +557,8 @@
557
  },
558
  "runtime": {
559
  "files_sha256": {
560
- "d3_runtime.py": "88fcaf3451edcc2139ffcb0db53ea4f9d03152e2736e0ffbb47386b40f618d52",
561
- "d3_fast.py": "c8f6e74968e2835732e0865814b98a21e4b604c80ecb0416c270219eb8e64c05",
562
  "d3_kernels.py": "8f7534ca1e1846ebf7c4c73058002f3be4dbf0d5d426f0815150ae0cbe7677bd",
563
  "modeling_d3.py": "9a718530f18d33d706a44d79be463ff43963fa3a9f808ce934a6489fd09042aa",
564
  "pipeline_d3.py": "c0975a91316bcda9c09c5f14bf634ceec94e6980ed7e76a29b718fb451fe4091",
@@ -581,11 +581,11 @@
581
  }
582
  ]
583
  },
584
- "built_utc": "2026-10-10T21:45:40+00:00",
585
  "files_sha256": {
586
  "LICENSE": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4",
587
  "NOTICE": "ae7ffb4d788c076d655394f0f116ad4b7de54e3bca9b655df5c669ea5bae74f6",
588
- "README.md": "4aeebb539c454a6c663b887b9bff76ec7107ae711ac03f3778a0f2156bb89b09",
589
  "assets/banner.png": "d621431eb5d1b20650a35a2e27c30f372631592cabff260679f12be9813eebc5",
590
  "assets/example-receipt.png": "b9dbb8b103bacd45f1de824d844a3c07b81d57cb1a7466712ef060ad7dcb3926",
591
  "assets/index-areas.png": "cea16dca531b6b9bb039e3199061e22aefc619ec7a3e5d5455f00bd20ae25e6d",
@@ -593,10 +593,10 @@
593
  "chat_template.jinja": "a4aee8afcf2e0711942cf848899be66016f8d14a889ff9ede07bca099c28f715",
594
  "config.json": "9c3e6eea217964096c7b032285bab6757720a847fbb9d0a04e551d2b1606c0eb",
595
  "d3_engine.py": "ab638d785325d944d3dac891f77448dfc91cad1b8d55a7302bd527c5f1e0e251",
596
- "d3_fast.py": "c8f6e74968e2835732e0865814b98a21e4b604c80ecb0416c270219eb8e64c05",
597
  "d3_format.py": "187a0f359f6f89a844e723377769556f78133b118851e702e4b0fe5123ccb0f1",
598
  "d3_kernels.py": "8f7534ca1e1846ebf7c4c73058002f3be4dbf0d5d426f0815150ae0cbe7677bd",
599
- "d3_runtime.py": "88fcaf3451edcc2139ffcb0db53ea4f9d03152e2736e0ffbb47386b40f618d52",
600
  "d3_server.py": "11211faa83fee50b957903f0d596c153b0921cb5414f18edee31d8dac76db9fc",
601
  "decision_config.json": "0269c72ac055d8149a7a778c477780af361f4c1cde3fd0e5ba9af791453ece18",
602
  "merges.txt": "a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d",
@@ -626,10 +626,10 @@
626
  "chat_template.jinja": 7756,
627
  "config.json": 3093,
628
  "d3_engine.py": 3726,
629
- "d3_fast.py": 21284,
630
  "d3_format.py": 4881,
631
  "d3_kernels.py": 16129,
632
- "d3_runtime.py": 57795,
633
  "d3_server.py": 8333,
634
  "decision_config.json": 5502,
635
  "merges.txt": 3353259,
 
557
  },
558
  "runtime": {
559
  "files_sha256": {
560
+ "d3_runtime.py": "139ece85007c5771b5e374da9658dc8832eb23aabfeaabe29f18e56d59d7f82f",
561
+ "d3_fast.py": "68a1fb9a2c3bde9ac2763bf504decae592ca12722698fbde1b39a31262955535",
562
  "d3_kernels.py": "8f7534ca1e1846ebf7c4c73058002f3be4dbf0d5d426f0815150ae0cbe7677bd",
563
  "modeling_d3.py": "9a718530f18d33d706a44d79be463ff43963fa3a9f808ce934a6489fd09042aa",
564
  "pipeline_d3.py": "c0975a91316bcda9c09c5f14bf634ceec94e6980ed7e76a29b718fb451fe4091",
 
581
  }
582
  ]
583
  },
584
+ "built_utc": "2026-10-11T00:16:22+00:00",
585
  "files_sha256": {
586
  "LICENSE": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4",
587
  "NOTICE": "ae7ffb4d788c076d655394f0f116ad4b7de54e3bca9b655df5c669ea5bae74f6",
588
+ "README.md": "9b7836b3165c07291603c1a61c179dc0c6a40bbe495e4fdedb629a55f882edd2",
589
  "assets/banner.png": "d621431eb5d1b20650a35a2e27c30f372631592cabff260679f12be9813eebc5",
590
  "assets/example-receipt.png": "b9dbb8b103bacd45f1de824d844a3c07b81d57cb1a7466712ef060ad7dcb3926",
591
  "assets/index-areas.png": "cea16dca531b6b9bb039e3199061e22aefc619ec7a3e5d5455f00bd20ae25e6d",
 
593
  "chat_template.jinja": "a4aee8afcf2e0711942cf848899be66016f8d14a889ff9ede07bca099c28f715",
594
  "config.json": "9c3e6eea217964096c7b032285bab6757720a847fbb9d0a04e551d2b1606c0eb",
595
  "d3_engine.py": "ab638d785325d944d3dac891f77448dfc91cad1b8d55a7302bd527c5f1e0e251",
596
+ "d3_fast.py": "68a1fb9a2c3bde9ac2763bf504decae592ca12722698fbde1b39a31262955535",
597
  "d3_format.py": "187a0f359f6f89a844e723377769556f78133b118851e702e4b0fe5123ccb0f1",
598
  "d3_kernels.py": "8f7534ca1e1846ebf7c4c73058002f3be4dbf0d5d426f0815150ae0cbe7677bd",
599
+ "d3_runtime.py": "139ece85007c5771b5e374da9658dc8832eb23aabfeaabe29f18e56d59d7f82f",
600
  "d3_server.py": "11211faa83fee50b957903f0d596c153b0921cb5414f18edee31d8dac76db9fc",
601
  "decision_config.json": "0269c72ac055d8149a7a778c477780af361f4c1cde3fd0e5ba9af791453ece18",
602
  "merges.txt": "a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d",
 
626
  "chat_template.jinja": 7756,
627
  "config.json": 3093,
628
  "d3_engine.py": 3726,
629
+ "d3_fast.py": 22331,
630
  "d3_format.py": 4881,
631
  "d3_kernels.py": 16129,
632
+ "d3_runtime.py": 59432,
633
  "d3_server.py": 8333,
634
  "decision_config.json": 5502,
635
  "merges.txt": 3353259,
README.md CHANGED
@@ -31,7 +31,7 @@ tags:
31
  - **Jev Decision Index 0.3, public suite: 57.79**, measured with the official 0.3 kit on the released weights: all 140,178 public requests answered, none unsupported.
32
  - **+11.0 on the public suite over Decision 2.0** (its 9B model: 46.76 on the board), ahead in all five areas.
33
  - **Reads images:** multiple images per request (PNG, JPEG or WebP), given as paths, URLs, PIL images or base64 data URLs; every question of the request sees all of them.
34
- - **Speed:** a median of 19.4 ms for a text request and 151.9 ms for a request with an image, on one AMD Instinct MI325X GPU, one request at a time.
35
  - **Many questions, one call:** Choice, Yes / No and Score questions about the same input are answered together, each from its own forward pass over the input, with a probability for every option.
36
 
37
  ## Quickstart
 
31
  - **Jev Decision Index 0.3, public suite: 57.79**, measured with the official 0.3 kit on the released weights: all 140,178 public requests answered, none unsupported.
32
  - **+11.0 on the public suite over Decision 2.0** (its 9B model: 46.76 on the board), ahead in all five areas.
33
  - **Reads images:** multiple images per request (PNG, JPEG or WebP), given as paths, URLs, PIL images or base64 data URLs; every question of the request sees all of them.
34
+ - **Speed:** a median of 19.1 ms for a text request and 149.4 ms for a request with an image, on one AMD Instinct MI325X GPU, one request at a time.
35
  - **Many questions, one call:** Choice, Yes / No and Score questions about the same input are answered together, each from its own forward pass over the input, with a probability for every option.
36
 
37
  ## Quickstart
d3_fast.py CHANGED
@@ -71,6 +71,30 @@ def fusable(model: Any) -> str | None:
71
  return "needs " + ", ".join(missing) if missing else None
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  class FusedLayers:
75
  """The decoder layers and final norm of a Qwen3.5 text model through ``d3_kernels`` (eager values)."""
76
 
@@ -82,7 +106,10 @@ class FusedLayers:
82
  try:
83
  from . import d3_kernels as kernels
84
  except ImportError:
85
- kernels = importlib.import_module("d3_kernels")
 
 
 
86
  self.k = kernels
87
  self.torch = torch
88
  self.chunk = modeling.torch_chunk_gated_delta_rule
 
71
  return "needs " + ", ".join(missing) if missing else None
72
 
73
 
74
+ def kernels_next_to_this_file():
75
+ """``d3_kernels.py`` of this file's directory, imported by path once per file (see ``d3_runtime.fast_module``)."""
76
+ import hashlib
77
+ import importlib.util
78
+ import sys
79
+ from pathlib import Path
80
+
81
+ # Not resolved: in a Hub snapshot the .py names are links to blobs without a suffix.
82
+ path = Path(__file__).absolute().with_name("d3_kernels.py")
83
+ name = f"d3_kernels_{hashlib.sha256(str(path).encode()).hexdigest()[:16]}"
84
+ if name not in sys.modules:
85
+ spec = importlib.util.spec_from_file_location(name, str(path))
86
+ if spec is None or spec.loader is None:
87
+ raise ImportError(f"no loader for {path}")
88
+ module = importlib.util.module_from_spec(spec)
89
+ sys.modules[name] = module
90
+ try:
91
+ spec.loader.exec_module(module)
92
+ except BaseException:
93
+ del sys.modules[name]
94
+ raise
95
+ return sys.modules[name]
96
+
97
+
98
  class FusedLayers:
99
  """The decoder layers and final norm of a Qwen3.5 text model through ``d3_kernels`` (eager values)."""
100
 
 
106
  try:
107
  from . import d3_kernels as kernels
108
  except ImportError:
109
+ try:
110
+ kernels = importlib.import_module("d3_kernels")
111
+ except ImportError:
112
+ kernels = kernels_next_to_this_file()
113
  self.k = kernels
114
  self.torch = torch
115
  self.chunk = modeling.torch_chunk_gated_delta_rule
d3_runtime.py CHANGED
@@ -463,6 +463,39 @@ def sha256_file(path: Path) -> str:
463
  return digest.hexdigest()
464
 
465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  def resolve_dir(
467
  name_or_path: str | os.PathLike, revision: str | None = None, **hub: Any
468
  ) -> Path:
@@ -799,8 +832,14 @@ class D3:
799
  self.image_unavailable = (
800
  f"the image processor failed to load ({type(exc).__name__}: {exc})"
801
  )
802
- self.fast_skipped = None if d3_fast else "d3_fast.py is not present"
803
- self.fast = d3_fast.install(self) if d3_fast else None
 
 
 
 
 
 
804
  self.loaded_seconds = time.perf_counter() - started
805
 
806
  @classmethod
 
463
  return digest.hexdigest()
464
 
465
 
466
+ def load_file_module(path: Path):
467
+ """Import a flat package file by its path, once per file (two checkpoints can share a process)."""
468
+ import importlib.util
469
+ import sys
470
+
471
+ # Not resolved: in a Hub snapshot the .py name is a link to a blob without a suffix, which has no loader.
472
+ path = Path(path).absolute()
473
+ name = f"{path.stem}_{hashlib.sha256(str(path).encode()).hexdigest()[:16]}"
474
+ if name not in sys.modules:
475
+ spec = importlib.util.spec_from_file_location(name, str(path))
476
+ if spec is None or spec.loader is None:
477
+ raise ImportError(f"no loader for {path}")
478
+ module = importlib.util.module_from_spec(spec)
479
+ sys.modules[name] = module
480
+ try:
481
+ spec.loader.exec_module(module)
482
+ except BaseException:
483
+ del sys.modules[name]
484
+ raise
485
+ return sys.modules[name]
486
+
487
+
488
+ def fast_module(root: Path):
489
+ """``d3_fast.py`` of the checkpoint directory when it is not importable as a module.
490
+
491
+ ``AutoModel.from_pretrained(..., trust_remote_code=True)`` copies only the modeling files and their
492
+ ``from .x import y`` imports into its module cache; the package's own copy (verified against
493
+ ``MODEL_MANIFEST.json``) is next to the weights.
494
+ """
495
+ path = Path(root) / "d3_fast.py"
496
+ return load_file_module(path) if path.is_file() else None
497
+
498
+
499
  def resolve_dir(
500
  name_or_path: str | os.PathLike, revision: str | None = None, **hub: Any
501
  ) -> Path:
 
832
  self.image_unavailable = (
833
  f"the image processor failed to load ({type(exc).__name__}: {exc})"
834
  )
835
+ fast, reason = d3_fast, "d3_fast.py is not present"
836
+ if fast is None:
837
+ try:
838
+ fast = fast_module(self.root)
839
+ except Exception as exc: # noqa: BLE001 - the plain path always loads
840
+ reason = f"d3_fast.py failed to import ({type(exc).__name__}: {exc})"
841
+ self.fast_skipped = None if fast else reason
842
+ self.fast = fast.install(self) if fast else None
843
  self.loaded_seconds = time.perf_counter() - started
844
 
845
  @classmethod