llm-dequant 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llm_dequant/__init__.py +4 -0
- llm_dequant/cli.py +69 -0
- llm_dequant/model.py +376 -0
- llm_dequant/nvfp4.py +154 -0
- llm_dequant-0.1.0.dist-info/METADATA +184 -0
- llm_dequant-0.1.0.dist-info/RECORD +10 -0
- llm_dequant-0.1.0.dist-info/WHEEL +5 -0
- llm_dequant-0.1.0.dist-info/entry_points.txt +2 -0
- llm_dequant-0.1.0.dist-info/licenses/LICENSE +202 -0
- llm_dequant-0.1.0.dist-info/top_level.txt +1 -0
llm_dequant/__init__.py
ADDED
llm_dequant/cli.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Command-line interface for llm-dequant."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .model import DEFAULT_SHARD_BYTES, DTYPES, convert, inspect_checkpoint, verify
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main(argv: list[str] | None = None) -> int:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="llm-dequant",
|
|
17
|
+
description=(
|
|
18
|
+
"Dequantize compressed-tensors NVFP4 checkpoints to dense "
|
|
19
|
+
"safetensors (streaming, constant memory)."
|
|
20
|
+
),
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument("--version", action="version", version=__version__)
|
|
23
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
24
|
+
|
|
25
|
+
p_convert = sub.add_parser("convert", help="dequantize a checkpoint")
|
|
26
|
+
p_convert.add_argument("src", type=Path, help="compressed checkpoint directory")
|
|
27
|
+
p_convert.add_argument("dst", type=Path, help="output directory")
|
|
28
|
+
p_convert.add_argument(
|
|
29
|
+
"--dtype", choices=sorted(DTYPES), default="bf16",
|
|
30
|
+
help="output dtype (default: bf16)",
|
|
31
|
+
)
|
|
32
|
+
p_convert.add_argument(
|
|
33
|
+
"--shard-gb", type=float, default=DEFAULT_SHARD_BYTES / 1024**3,
|
|
34
|
+
help="target output shard size in GiB (default: 8)",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
p_verify = sub.add_parser(
|
|
38
|
+
"verify",
|
|
39
|
+
help="round-trip check: dequantize + repack sampled modules, compare bytes",
|
|
40
|
+
)
|
|
41
|
+
p_verify.add_argument("src", type=Path, help="compressed checkpoint directory")
|
|
42
|
+
p_verify.add_argument("--sample", type=int, default=8,
|
|
43
|
+
help="number of random packed modules to check (default: 8)")
|
|
44
|
+
p_verify.add_argument("--seed", type=int, default=0, help="sampling seed")
|
|
45
|
+
|
|
46
|
+
p_inspect = sub.add_parser("inspect", help="show checkpoint quantization summary")
|
|
47
|
+
p_inspect.add_argument("src", type=Path, help="checkpoint directory")
|
|
48
|
+
|
|
49
|
+
args = parser.parse_args(argv)
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
if args.command == "convert":
|
|
53
|
+
if args.shard_gb <= 0:
|
|
54
|
+
parser.error("--shard-gb must be positive")
|
|
55
|
+
convert(args.src, args.dst, dtype=args.dtype,
|
|
56
|
+
shard_bytes=int(args.shard_gb * 1024**3))
|
|
57
|
+
elif args.command == "verify":
|
|
58
|
+
result = verify(args.src, sample=args.sample, seed=args.seed)
|
|
59
|
+
return 0 if not result["failures"] else 1
|
|
60
|
+
elif args.command == "inspect":
|
|
61
|
+
inspect_checkpoint(args.src)
|
|
62
|
+
except (FileNotFoundError, ValueError) as exc:
|
|
63
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
64
|
+
return 2
|
|
65
|
+
return 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
sys.exit(main())
|
llm_dequant/model.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
Checkpoint-level streaming conversion: compressed-tensors NVFP4 -> dense safetensors.
|
|
4
|
+
|
|
5
|
+
Handles HuggingFace sharded checkpoints (model.safetensors.index.json) and
|
|
6
|
+
single-file checkpoints (model.safetensors). Memory use is bounded by the
|
|
7
|
+
largest single module plus one output shard buffer, regardless of model size.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import shutil
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import torch
|
|
19
|
+
from safetensors import safe_open
|
|
20
|
+
from safetensors.torch import save_file
|
|
21
|
+
|
|
22
|
+
from .nvfp4 import GROUP_SIZE, dequantize_nvfp4, pack_fp4, unpack_fp4
|
|
23
|
+
|
|
24
|
+
__all__ = ["CheckpointReader", "convert", "verify", "inspect_checkpoint"]
|
|
25
|
+
|
|
26
|
+
SUPPORTED_FORMATS = {"nvfp4-pack-quantized"}
|
|
27
|
+
|
|
28
|
+
# local (per-module) tensor names that belong to a packed module
|
|
29
|
+
PACKED_PARAM_NAMES = frozenset(
|
|
30
|
+
{
|
|
31
|
+
"weight_packed",
|
|
32
|
+
"weight_scale",
|
|
33
|
+
"weight_global_scale",
|
|
34
|
+
"weight_zero_point",
|
|
35
|
+
"input_global_scale",
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
PASSTHROUGH_FILE_SUFFIXES = (".json", ".jinja", ".txt", ".model", ".py", ".md")
|
|
40
|
+
PASSTHROUGH_FILE_NAMES = ("LICENSE", "LICENSE.txt", "NOTICE")
|
|
41
|
+
DEFAULT_SHARD_BYTES = 8 * 1024**3
|
|
42
|
+
|
|
43
|
+
DTYPES = {
|
|
44
|
+
"bf16": torch.bfloat16,
|
|
45
|
+
"fp16": torch.float16,
|
|
46
|
+
"fp32": torch.float32,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class Module:
|
|
52
|
+
"""One logical module: either a packed quantized weight or a passthrough tensor."""
|
|
53
|
+
|
|
54
|
+
name: str # module prefix (packed) or full tensor name
|
|
55
|
+
tensors: dict[str, str] = field(default_factory=dict) # local name -> full name
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def is_packed(self) -> bool:
|
|
59
|
+
return "weight_packed" in self.tensors
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class CheckpointReader:
|
|
63
|
+
"""Lazily reads tensors from a sharded or single-file safetensors checkpoint."""
|
|
64
|
+
|
|
65
|
+
def __init__(self, src: Path):
|
|
66
|
+
self.src = Path(src)
|
|
67
|
+
index_path = self.src / "model.safetensors.index.json"
|
|
68
|
+
single_path = self.src / "model.safetensors"
|
|
69
|
+
if index_path.exists():
|
|
70
|
+
index = json.loads(index_path.read_text())
|
|
71
|
+
self.weight_map: dict[str, str] = index["weight_map"]
|
|
72
|
+
for fname in set(self.weight_map.values()):
|
|
73
|
+
self._check_shard_name(fname)
|
|
74
|
+
elif single_path.exists():
|
|
75
|
+
with safe_open(single_path, framework="pt", device="cpu") as f:
|
|
76
|
+
self.weight_map = {k: "model.safetensors" for k in f.keys()}
|
|
77
|
+
else:
|
|
78
|
+
raise FileNotFoundError(
|
|
79
|
+
f"no model.safetensors.index.json or model.safetensors in {self.src}"
|
|
80
|
+
)
|
|
81
|
+
self._handles: dict[str, object] = {}
|
|
82
|
+
|
|
83
|
+
def _check_shard_name(self, fname: str) -> None:
|
|
84
|
+
"""index.json is untrusted input: shard names must be plain filenames
|
|
85
|
+
inside the checkpoint directory (no separators, no '..', not absolute)."""
|
|
86
|
+
p = Path(fname)
|
|
87
|
+
if p.is_absolute() or p.name != fname or fname in ("", ".", ".."):
|
|
88
|
+
raise ValueError(
|
|
89
|
+
f"refusing suspicious shard filename in index.json: {fname!r}"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def tensor(self, full_name: str) -> torch.Tensor:
|
|
93
|
+
fname = self.weight_map[full_name]
|
|
94
|
+
if fname not in self._handles:
|
|
95
|
+
self._handles[fname] = safe_open(
|
|
96
|
+
self.src / fname, framework="pt", device="cpu"
|
|
97
|
+
)
|
|
98
|
+
return self._handles[fname].get_tensor(full_name)
|
|
99
|
+
|
|
100
|
+
def modules(self) -> list[Module]:
|
|
101
|
+
"""Group tensor names into modules, preserving first-seen order."""
|
|
102
|
+
by_key: dict[str, Module] = {}
|
|
103
|
+
order: list[str] = []
|
|
104
|
+
for full in self.weight_map:
|
|
105
|
+
prefix, _, local = full.rpartition(".")
|
|
106
|
+
if prefix and local in PACKED_PARAM_NAMES:
|
|
107
|
+
key = prefix
|
|
108
|
+
else:
|
|
109
|
+
key, local = full, ""
|
|
110
|
+
if key not in by_key:
|
|
111
|
+
by_key[key] = Module(name=key)
|
|
112
|
+
order.append(key)
|
|
113
|
+
by_key[key].tensors[local] = full
|
|
114
|
+
return [by_key[k] for k in order]
|
|
115
|
+
|
|
116
|
+
def load_config(self) -> dict:
|
|
117
|
+
cfg_path = self.src / "config.json"
|
|
118
|
+
if not cfg_path.exists():
|
|
119
|
+
raise FileNotFoundError(f"missing config.json in {self.src}")
|
|
120
|
+
return json.loads(cfg_path.read_text())
|
|
121
|
+
|
|
122
|
+
def detect_format(self) -> str:
|
|
123
|
+
qc = self.load_config().get("quantization_config")
|
|
124
|
+
if qc is None:
|
|
125
|
+
raise ValueError("config.json has no quantization_config — nothing to dequantize")
|
|
126
|
+
fmt = qc.get("format")
|
|
127
|
+
if fmt not in SUPPORTED_FORMATS:
|
|
128
|
+
raise ValueError(
|
|
129
|
+
f"unsupported compression format {fmt!r}; supported: {sorted(SUPPORTED_FORMATS)}"
|
|
130
|
+
)
|
|
131
|
+
groups = qc.get("config_groups", {})
|
|
132
|
+
for gname, group in groups.items():
|
|
133
|
+
w = group.get("weights") or {}
|
|
134
|
+
if w.get("num_bits") != 4 or w.get("type") != "float":
|
|
135
|
+
raise ValueError(f"{gname}: expected 4-bit float weights, got {w}")
|
|
136
|
+
if w.get("group_size") != GROUP_SIZE:
|
|
137
|
+
raise ValueError(
|
|
138
|
+
f"{gname}: group_size {w.get('group_size')} != {GROUP_SIZE}"
|
|
139
|
+
)
|
|
140
|
+
if not w.get("symmetric", True):
|
|
141
|
+
raise ValueError("asymmetric NVFP4 is not supported")
|
|
142
|
+
return fmt
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _dequant_module(reader: CheckpointReader, mod: Module, dtype: torch.dtype) -> torch.Tensor:
|
|
146
|
+
if "weight_zero_point" in mod.tensors:
|
|
147
|
+
raise ValueError(f"{mod.name}: asymmetric NVFP4 (zero point present) not supported")
|
|
148
|
+
packed = reader.tensor(mod.tensors["weight_packed"])
|
|
149
|
+
scale = reader.tensor(mod.tensors["weight_scale"])
|
|
150
|
+
gs_name = mod.tensors.get("weight_global_scale")
|
|
151
|
+
global_scale = reader.tensor(gs_name) if gs_name else None
|
|
152
|
+
return dequantize_nvfp4(packed, scale, global_scale, dtype=dtype)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class _ShardWriter:
|
|
156
|
+
"""Accumulates tensors and writes ~shard_bytes safetensors shards."""
|
|
157
|
+
|
|
158
|
+
def __init__(self, dst: Path, shard_bytes: int):
|
|
159
|
+
self.dst = dst
|
|
160
|
+
self.shard_bytes = shard_bytes
|
|
161
|
+
self.buffer: dict[str, torch.Tensor] = {}
|
|
162
|
+
self.buffered = 0
|
|
163
|
+
self.shards: list[list[str]] = [] # tensor names per shard
|
|
164
|
+
self._seen: set[str] = set()
|
|
165
|
+
|
|
166
|
+
def add(self, name: str, tensor: torch.Tensor) -> None:
|
|
167
|
+
if name in self._seen:
|
|
168
|
+
raise ValueError(
|
|
169
|
+
f"duplicate output tensor name {name!r} — the checkpoint "
|
|
170
|
+
"contains both a packed and a dense tensor mapping to the "
|
|
171
|
+
"same dequantized name; refusing to silently overwrite"
|
|
172
|
+
)
|
|
173
|
+
self._seen.add(name)
|
|
174
|
+
self.buffer[name] = tensor
|
|
175
|
+
self.buffered += tensor.numel() * tensor.element_size()
|
|
176
|
+
if self.buffered >= self.shard_bytes:
|
|
177
|
+
self.flush()
|
|
178
|
+
|
|
179
|
+
def flush(self) -> None:
|
|
180
|
+
if not self.buffer:
|
|
181
|
+
return
|
|
182
|
+
idx = len(self.shards) + 1
|
|
183
|
+
save_file(self.buffer, str(self.dst / f"model-{idx:05d}.safetensors"),
|
|
184
|
+
metadata={"format": "pt"})
|
|
185
|
+
self.shards.append(list(self.buffer.keys()))
|
|
186
|
+
self.buffer = {}
|
|
187
|
+
self.buffered = 0
|
|
188
|
+
|
|
189
|
+
def finalize(self) -> dict[str, str]:
|
|
190
|
+
"""Rename shards to canonical -of- form; return tensor -> shard map."""
|
|
191
|
+
self.flush()
|
|
192
|
+
total = len(self.shards)
|
|
193
|
+
weight_map: dict[str, str] = {}
|
|
194
|
+
for i, names in enumerate(self.shards, 1):
|
|
195
|
+
src = self.dst / f"model-{i:05d}.safetensors"
|
|
196
|
+
canon = f"model-{i:05d}-of-{total:05d}.safetensors"
|
|
197
|
+
os.replace(src, self.dst / canon)
|
|
198
|
+
for n in names:
|
|
199
|
+
weight_map[n] = canon
|
|
200
|
+
return weight_map
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def convert(
|
|
204
|
+
src: Path,
|
|
205
|
+
dst: Path,
|
|
206
|
+
dtype: str = "bf16",
|
|
207
|
+
shard_bytes: int = DEFAULT_SHARD_BYTES,
|
|
208
|
+
progress_every: int = 2000,
|
|
209
|
+
log=print,
|
|
210
|
+
) -> dict:
|
|
211
|
+
"""
|
|
212
|
+
Convert a compressed NVFP4 checkpoint at ``src`` into a dense checkpoint
|
|
213
|
+
at ``dst``. Returns a summary dict.
|
|
214
|
+
"""
|
|
215
|
+
src, dst = Path(src), Path(dst)
|
|
216
|
+
if dst.resolve() == src.resolve():
|
|
217
|
+
raise ValueError("src and dst must differ")
|
|
218
|
+
if dtype not in DTYPES:
|
|
219
|
+
raise ValueError(f"unknown dtype {dtype!r}; choose from {sorted(DTYPES)}")
|
|
220
|
+
torch_dtype = DTYPES[dtype]
|
|
221
|
+
|
|
222
|
+
reader = CheckpointReader(src)
|
|
223
|
+
fmt = reader.detect_format()
|
|
224
|
+
modules = reader.modules()
|
|
225
|
+
n_packed = sum(1 for m in modules if m.is_packed)
|
|
226
|
+
log(f"format={fmt} modules={len(modules)} packed={n_packed} -> {dtype}")
|
|
227
|
+
if n_packed == 0:
|
|
228
|
+
raise ValueError("no packed modules found; is this really a compressed checkpoint?")
|
|
229
|
+
|
|
230
|
+
dst.mkdir(parents=True, exist_ok=True)
|
|
231
|
+
|
|
232
|
+
# passthrough sidecar files (tokenizer, templates, ...) except the ones we rewrite
|
|
233
|
+
for f in sorted(src.iterdir()):
|
|
234
|
+
if f.name in ("config.json", "model.safetensors.index.json"):
|
|
235
|
+
continue
|
|
236
|
+
if f.name.endswith(".safetensors"):
|
|
237
|
+
continue
|
|
238
|
+
if f.name.endswith(PASSTHROUGH_FILE_SUFFIXES) or f.name in PASSTHROUGH_FILE_NAMES:
|
|
239
|
+
shutil.copy2(f, dst / f.name)
|
|
240
|
+
|
|
241
|
+
cfg = reader.load_config()
|
|
242
|
+
cfg.pop("quantization_config", None)
|
|
243
|
+
cfg["torch_dtype"] = {"bf16": "bfloat16", "fp16": "float16", "fp32": "float32"}[dtype]
|
|
244
|
+
(dst / "config.json").write_text(json.dumps(cfg, indent=2))
|
|
245
|
+
|
|
246
|
+
writer = _ShardWriter(dst, shard_bytes)
|
|
247
|
+
done = 0
|
|
248
|
+
for mod in modules:
|
|
249
|
+
if mod.is_packed:
|
|
250
|
+
writer.add(mod.name + ".weight", _dequant_module(reader, mod, torch_dtype))
|
|
251
|
+
else:
|
|
252
|
+
# single passthrough tensor; key "" holds the full name
|
|
253
|
+
full = mod.tensors.get("") or mod.tensors.get("weight")
|
|
254
|
+
if full is None:
|
|
255
|
+
raise ValueError(
|
|
256
|
+
f"module {mod.name!r} has quantization params "
|
|
257
|
+
f"{sorted(mod.tensors)} but no weight_packed — "
|
|
258
|
+
"corrupt or unsupported checkpoint layout"
|
|
259
|
+
)
|
|
260
|
+
writer.add(full, reader.tensor(full))
|
|
261
|
+
done += 1
|
|
262
|
+
if progress_every and done % progress_every == 0:
|
|
263
|
+
log(f" {done}/{len(modules)} modules")
|
|
264
|
+
|
|
265
|
+
weight_map = writer.finalize()
|
|
266
|
+
total_bytes = sum(
|
|
267
|
+
(dst / f).stat().st_size for f in os.listdir(dst) if f.endswith(".safetensors")
|
|
268
|
+
)
|
|
269
|
+
(dst / "model.safetensors.index.json").write_text(
|
|
270
|
+
json.dumps(
|
|
271
|
+
{"metadata": {"total_size": total_bytes}, "weight_map": weight_map},
|
|
272
|
+
indent=2,
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
summary = {
|
|
276
|
+
"modules": len(modules),
|
|
277
|
+
"packed": n_packed,
|
|
278
|
+
"tensors": len(weight_map),
|
|
279
|
+
"shards": len(writer.shards),
|
|
280
|
+
"bytes": total_bytes,
|
|
281
|
+
}
|
|
282
|
+
log(f"DONE shards={summary['shards']} tensors={summary['tensors']} "
|
|
283
|
+
f"size={total_bytes / 1e9:.1f}GB")
|
|
284
|
+
return summary
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def verify(src: Path, sample: int = 8, seed: int = 0, log=print) -> dict:
|
|
288
|
+
"""
|
|
289
|
+
Round-trip check on ``sample`` packed modules of the SOURCE checkpoint:
|
|
290
|
+
dequantize with this library, re-quantize with nearest-E2M1 packing, and
|
|
291
|
+
require the repacked bytes to equal the originals bit-for-bit.
|
|
292
|
+
|
|
293
|
+
Every correctly dequantized value sits exactly on the scaled FP4 lattice,
|
|
294
|
+
so errors in unpacking, scale layout, group mapping, or global-scale
|
|
295
|
+
handling produce byte mismatches. Non-finite scales are counted as
|
|
296
|
+
failures. Note this establishes *self-consistency against the actual
|
|
297
|
+
checkpoint bytes*; conformance to the NVFP4 format spec itself is
|
|
298
|
+
established separately by the test-suite equivalence check against the
|
|
299
|
+
reference ``compressed-tensors`` implementation.
|
|
300
|
+
"""
|
|
301
|
+
reader = CheckpointReader(src)
|
|
302
|
+
reader.detect_format()
|
|
303
|
+
packed_mods = [m for m in reader.modules() if m.is_packed]
|
|
304
|
+
if not packed_mods:
|
|
305
|
+
raise ValueError("no packed modules to verify")
|
|
306
|
+
|
|
307
|
+
gen = torch.Generator().manual_seed(seed)
|
|
308
|
+
idx = torch.randperm(len(packed_mods), generator=gen)[: min(sample, len(packed_mods))]
|
|
309
|
+
failures = []
|
|
310
|
+
for i in idx.tolist():
|
|
311
|
+
mod = packed_mods[i]
|
|
312
|
+
packed = reader.tensor(mod.tensors["weight_packed"])
|
|
313
|
+
scale = reader.tensor(mod.tensors["weight_scale"]).to(torch.float32)
|
|
314
|
+
gs_name = mod.tensors.get("weight_global_scale")
|
|
315
|
+
gs = reader.tensor(gs_name).to(torch.float32) if gs_name else None
|
|
316
|
+
|
|
317
|
+
try:
|
|
318
|
+
dense = dequantize_nvfp4(packed, scale, gs, dtype=torch.float32)
|
|
319
|
+
except ValueError as exc:
|
|
320
|
+
log(f" {mod.name}: FAIL ({exc})")
|
|
321
|
+
failures.append(mod.name)
|
|
322
|
+
continue
|
|
323
|
+
eff_scale = scale / gs if gs is not None else scale
|
|
324
|
+
expanded = eff_scale.repeat_interleave(GROUP_SIZE, dim=-1)
|
|
325
|
+
# zero-scale groups carry no magnitude information (dense is 0 either
|
|
326
|
+
# way); reuse the original codes there so they don't false-fail
|
|
327
|
+
orig_vals = unpack_fp4(packed)
|
|
328
|
+
codes = torch.where(expanded != 0, dense / expanded, orig_vals)
|
|
329
|
+
repacked = pack_fp4(codes)
|
|
330
|
+
|
|
331
|
+
ok = torch.equal(repacked, packed)
|
|
332
|
+
residual = None
|
|
333
|
+
if not ok:
|
|
334
|
+
# -0.0 codes (0x8) dequantize to 0.0 and legitimately repack as
|
|
335
|
+
# +0.0 (0x0); torch.equal on the unpacked VALUES treats those as
|
|
336
|
+
# equal while any real magnitude/sign mismatch still fails
|
|
337
|
+
new_vals = unpack_fp4(repacked)
|
|
338
|
+
if torch.equal(orig_vals, new_vals):
|
|
339
|
+
ok = True
|
|
340
|
+
else:
|
|
341
|
+
residual = int((repacked != packed).sum())
|
|
342
|
+
log(f" {mod.name}: {'OK' if ok else f'FAIL ({residual} bytes differ)'}")
|
|
343
|
+
if not ok:
|
|
344
|
+
failures.append(mod.name)
|
|
345
|
+
|
|
346
|
+
result = {"sampled": len(idx), "failures": failures}
|
|
347
|
+
log(f"VERIFY {'PASSED' if not failures else 'FAILED'} "
|
|
348
|
+
f"({len(idx) - len(failures)}/{len(idx)} modules)")
|
|
349
|
+
return result
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def inspect_checkpoint(src: Path, log=print) -> dict:
|
|
353
|
+
"""Print and return summary stats for a compressed checkpoint."""
|
|
354
|
+
reader = CheckpointReader(src)
|
|
355
|
+
cfg = reader.load_config()
|
|
356
|
+
qc = cfg.get("quantization_config", {})
|
|
357
|
+
modules = reader.modules()
|
|
358
|
+
packed = [m for m in modules if m.is_packed]
|
|
359
|
+
|
|
360
|
+
packed_bytes = 0
|
|
361
|
+
dense_bytes_est = 0
|
|
362
|
+
for m in packed[:1]: # shape probe on one module
|
|
363
|
+
t = reader.tensor(m.tensors["weight_packed"])
|
|
364
|
+
log(f" example packed module {m.name}: packed shape {tuple(t.shape)}")
|
|
365
|
+
info = {
|
|
366
|
+
"format": qc.get("format"),
|
|
367
|
+
"quant_method": qc.get("quant_method"),
|
|
368
|
+
"ignore_count": len(qc.get("ignore", [])),
|
|
369
|
+
"modules": len(modules),
|
|
370
|
+
"packed_modules": len(packed),
|
|
371
|
+
"tensors": len(reader.weight_map),
|
|
372
|
+
"architectures": cfg.get("architectures"),
|
|
373
|
+
}
|
|
374
|
+
for k, v in info.items():
|
|
375
|
+
log(f" {k}: {v}")
|
|
376
|
+
return info
|
llm_dequant/nvfp4.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""
|
|
3
|
+
NVFP4 (E2M1, group-16, FP8-E4M3 scales) pack/unpack/dequantize math.
|
|
4
|
+
|
|
5
|
+
This is a standalone reimplementation of the ``nvfp4-pack-quantized``
|
|
6
|
+
compression format produced by llm-compressor / compressed-tensors
|
|
7
|
+
(https://github.com/vllm-project/llm-compressor). It has no dependency on
|
|
8
|
+
those libraries; only torch is required.
|
|
9
|
+
|
|
10
|
+
Format specification (as emitted by compressed-tensors >= 0.10):
|
|
11
|
+
|
|
12
|
+
weight_packed uint8 [..., m, n/2] two FP4 codes per byte,
|
|
13
|
+
LOW nibble = even column,
|
|
14
|
+
HIGH nibble = odd column
|
|
15
|
+
weight_scale fp8-e4m3 [..., m, n/16] one scale per group of 16
|
|
16
|
+
consecutive columns
|
|
17
|
+
weight_global_scale fp32 scalar per-module global scale
|
|
18
|
+
|
|
19
|
+
FP4 code: bit 3 = sign, bits 0-2 = index into the E2M1 magnitude table
|
|
20
|
+
[0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0]
|
|
21
|
+
|
|
22
|
+
Dequantization:
|
|
23
|
+
W[i, j] = e2m1(code[i, j]) * (scale[i, j // 16] / global_scale)
|
|
24
|
+
|
|
25
|
+
When ``weight_global_scale`` is absent the division is skipped.
|
|
26
|
+
|
|
27
|
+
All functions accept an optional leading batch dimension (fused MoE expert
|
|
28
|
+
tensors of shape [num_experts, m, n/2] work unchanged); grouping is always
|
|
29
|
+
along the LAST dimension.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import torch
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"E2M1_VALUES",
|
|
38
|
+
"unpack_fp4",
|
|
39
|
+
"pack_fp4",
|
|
40
|
+
"dequantize_nvfp4",
|
|
41
|
+
"GROUP_SIZE",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
# The eight non-negative values representable in FP4 E2M1
|
|
45
|
+
# (1 sign bit, 2 exponent bits, 1 mantissa bit).
|
|
46
|
+
E2M1_VALUES = (0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0)
|
|
47
|
+
|
|
48
|
+
_E2M1_LUT = torch.tensor(E2M1_VALUES, dtype=torch.float32)
|
|
49
|
+
|
|
50
|
+
# NVFP4 always uses groups of 16 elements along the input-feature dim.
|
|
51
|
+
GROUP_SIZE = 16
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def unpack_fp4(packed: torch.Tensor, dtype: torch.dtype = torch.float32) -> torch.Tensor:
|
|
55
|
+
"""
|
|
56
|
+
Unpack a uint8 tensor of packed FP4 codes into real values.
|
|
57
|
+
|
|
58
|
+
:param packed: uint8 tensor [..., n/2]; each byte holds two FP4 codes
|
|
59
|
+
(low nibble first).
|
|
60
|
+
:param dtype: dtype of the returned tensor.
|
|
61
|
+
:return: tensor [..., n] of FP4 values in ``dtype``.
|
|
62
|
+
"""
|
|
63
|
+
if packed.dtype != torch.uint8:
|
|
64
|
+
raise TypeError(f"packed tensor must be uint8, got {packed.dtype}")
|
|
65
|
+
|
|
66
|
+
low = packed & 0x0F
|
|
67
|
+
high = (packed >> 4) & 0x0F
|
|
68
|
+
# interleave: [..., n/2, 2] -> [..., n]
|
|
69
|
+
codes = torch.stack((low, high), dim=-1).reshape(*packed.shape[:-1], -1)
|
|
70
|
+
|
|
71
|
+
signs = (codes & 0x08).to(torch.bool)
|
|
72
|
+
magnitudes = (codes & 0x07).to(torch.long)
|
|
73
|
+
|
|
74
|
+
lut = _E2M1_LUT.to(device=packed.device)
|
|
75
|
+
values = lut[magnitudes]
|
|
76
|
+
values = torch.where(signs, -values, values)
|
|
77
|
+
return values.to(dtype)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def pack_fp4(values: torch.Tensor) -> torch.Tensor:
|
|
81
|
+
"""
|
|
82
|
+
Pack real values into FP4 codes (nearest E2M1 magnitude, ties toward the
|
|
83
|
+
smaller magnitude — identical behaviour to upstream compressed-tensors).
|
|
84
|
+
|
|
85
|
+
Used for verification round-trips and tests; the conversion path never
|
|
86
|
+
quantizes.
|
|
87
|
+
|
|
88
|
+
:param values: float tensor [..., n] with n even.
|
|
89
|
+
:return: uint8 tensor [..., n/2].
|
|
90
|
+
"""
|
|
91
|
+
if values.shape[-1] % 2 != 0:
|
|
92
|
+
raise ValueError("last dimension must be even to pack FP4 pairs")
|
|
93
|
+
|
|
94
|
+
lut = _E2M1_LUT.to(device=values.device, dtype=values.dtype)
|
|
95
|
+
diffs = (values.abs().unsqueeze(-1) - lut).abs()
|
|
96
|
+
indices = diffs.argmin(dim=-1) # first minimum wins ties (matches upstream)
|
|
97
|
+
codes = indices + (torch.signbit(values).to(torch.long) << 3)
|
|
98
|
+
|
|
99
|
+
pairs = codes.reshape(*codes.shape[:-1], -1, 2)
|
|
100
|
+
packed = pairs[..., 0] | (pairs[..., 1] << 4)
|
|
101
|
+
return packed.to(torch.uint8)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def dequantize_nvfp4(
|
|
105
|
+
packed: torch.Tensor,
|
|
106
|
+
scale: torch.Tensor,
|
|
107
|
+
global_scale: torch.Tensor | None = None,
|
|
108
|
+
dtype: torch.dtype = torch.bfloat16,
|
|
109
|
+
) -> torch.Tensor:
|
|
110
|
+
"""
|
|
111
|
+
Dequantize an nvfp4-pack-quantized weight back to a dense tensor.
|
|
112
|
+
|
|
113
|
+
:param packed: uint8 [..., m, n/2] packed FP4 codes.
|
|
114
|
+
:param scale: per-group scales [..., m, n/16]; any float dtype
|
|
115
|
+
(checkpoints store FP8-E4M3).
|
|
116
|
+
:param global_scale: optional scalar tensor; when present the effective
|
|
117
|
+
scale is ``scale / global_scale``.
|
|
118
|
+
:param dtype: output dtype (default bfloat16).
|
|
119
|
+
:return: dense weight [..., m, n] in ``dtype``.
|
|
120
|
+
"""
|
|
121
|
+
# fp32 intermediate: fp8 scales lose nothing, and v * s products stay exact
|
|
122
|
+
values = unpack_fp4(packed, dtype=torch.float32) # [..., m, n]
|
|
123
|
+
scale_f = scale.to(torch.float32)
|
|
124
|
+
|
|
125
|
+
n = values.shape[-1]
|
|
126
|
+
n_groups = scale_f.shape[-1]
|
|
127
|
+
if n_groups * GROUP_SIZE != n:
|
|
128
|
+
raise ValueError(
|
|
129
|
+
f"scale layout mismatch: weight has {n} columns but scale has "
|
|
130
|
+
f"{n_groups} groups (expected n = groups * {GROUP_SIZE})"
|
|
131
|
+
)
|
|
132
|
+
if scale_f.shape[:-1] != values.shape[:-1]:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"scale rows {tuple(scale.shape)} do not match weight rows "
|
|
135
|
+
f"{tuple(packed.shape)}"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if global_scale is not None:
|
|
139
|
+
gs = global_scale.to(torch.float32)
|
|
140
|
+
if gs.numel() != 1:
|
|
141
|
+
raise ValueError(f"global_scale must be scalar, got shape {tuple(gs.shape)}")
|
|
142
|
+
if not torch.isfinite(gs).all():
|
|
143
|
+
raise ValueError("global_scale is NaN or Inf; refusing to dequantize")
|
|
144
|
+
if gs.item() == 0.0:
|
|
145
|
+
raise ValueError("global_scale is zero; refusing to divide")
|
|
146
|
+
scale_f = scale_f / gs
|
|
147
|
+
|
|
148
|
+
if not torch.isfinite(scale_f).all():
|
|
149
|
+
raise ValueError(
|
|
150
|
+
"weight_scale contains NaN or Inf values; corrupt checkpoint"
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
expanded = scale_f.repeat_interleave(GROUP_SIZE, dim=-1) # [..., m, n]
|
|
154
|
+
return (values * expanded).to(dtype)
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-dequant
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dequantize compressed-tensors NVFP4 LLM checkpoints to dense safetensors (streaming, constant memory)
|
|
5
|
+
Author: Victor Cruz
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/vcruz305/llm-dequant
|
|
8
|
+
Keywords: nvfp4,quantization,dequantization,safetensors,llm,compressed-tensors,gguf
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: torch>=2.0
|
|
18
|
+
Requires-Dist: safetensors>=0.4
|
|
19
|
+
Requires-Dist: numpy>=1.24
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
<div align="center">
|
|
25
|
+
|
|
26
|
+
<img src="llm-dequant.png" alt="llm-dequant — stream NVFP4 compressed-tensors checkpoints back to dense safetensors" width="50%">
|
|
27
|
+
|
|
28
|
+
**Turn NVFP4-only model releases back into dense safetensors.**
|
|
29
|
+
|
|
30
|
+
Streaming, constant-memory dequantization of
|
|
31
|
+
[compressed-tensors](https://github.com/neuralmagic/compressed-tensors)
|
|
32
|
+
`nvfp4-pack-quantized` LLM checkpoints — a 300B-parameter MoE converts
|
|
33
|
+
on a few hundred MB of RAM.
|
|
34
|
+
|
|
35
|
+
[](https://github.com/vcruz305/llm-dequant/actions/workflows/tests.yml)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](pyproject.toml)
|
|
38
|
+
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Why this exists
|
|
44
|
+
|
|
45
|
+
A growing number of community models — abliterations, fine-tunes, supertunes —
|
|
46
|
+
are published **only** in NVFP4 compressed-tensors form. That single release
|
|
47
|
+
format locks out most of the ecosystem:
|
|
48
|
+
|
|
49
|
+
- `llama.cpp`'s `convert_hf_to_gguf.py` can't read compressed-tensors
|
|
50
|
+
checkpoints → **no GGUFs**
|
|
51
|
+
- fine-tuning frameworks expect dense weights → **no further training**
|
|
52
|
+
- weight surgery (MTP grafts, merges, pruning) needs real tensors → **no surgery**
|
|
53
|
+
|
|
54
|
+
The reference decompression path in `compressed-tensors`/`transformers`
|
|
55
|
+
materializes the whole model in memory, which is a non-starter at 300B scale.
|
|
56
|
+
|
|
57
|
+
`llm-dequant` fixes this with a purpose-built converter:
|
|
58
|
+
|
|
59
|
+
| | |
|
|
60
|
+
|---|---|
|
|
61
|
+
| 🌊 **Streaming** | module-by-module; peak RSS = one module + one shard buffer |
|
|
62
|
+
| 🎯 **Exact** | output is bit-identical to the reference implementation (CI-checked) |
|
|
63
|
+
| 🧾 **Standard output** | sharded safetensors + index, `quantization_config` stripped, tokenizer files copied — a normal dense HF checkpoint |
|
|
64
|
+
| 🪶 **Dependency-light** | `torch`, `safetensors`, `numpy`. No compressed-tensors, no transformers |
|
|
65
|
+
| 🔍 **Self-verifying** | `verify` proves round-trip byte-equality against *your actual checkpoint* before you commit to a 600GB write |
|
|
66
|
+
| 🛡️ **Defensive** | untrusted `index.json` path names rejected, NaN/Inf scales refuse loudly, unsupported formats never convert silently |
|
|
67
|
+
|
|
68
|
+
Born from converting a 295B MoE released as NVFP4-only into a full GGUF quant
|
|
69
|
+
sweep ([SuperHY3-abliterated-GGUF](https://huggingface.co/vcruz305/SuperHY3-abliterated-GGUF)).
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install llm-dequant # from PyPI (published releases)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
or straight from GitHub (works on any commit, no release needed):
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install git+https://github.com/vcruz305/llm-dequant.git
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Both pull in `torch`, `safetensors`, and `numpy` automatically. For a
|
|
84
|
+
CPU-only torch (much smaller download):
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
88
|
+
pip install llm-dequant
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Quickstart
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# 1. what is this checkpoint?
|
|
95
|
+
llm-dequant inspect /models/SomeModel-NVFP4
|
|
96
|
+
|
|
97
|
+
# 2. prove the math round-trips on THIS checkpoint (seconds, no writes)
|
|
98
|
+
llm-dequant verify /models/SomeModel-NVFP4 --sample 16
|
|
99
|
+
|
|
100
|
+
# 3. convert (bf16 default; fp16/fp32 available)
|
|
101
|
+
llm-dequant convert /models/SomeModel-NVFP4 /models/SomeModel-BF16
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Then use the output like any dense checkpoint:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python llama.cpp/convert_hf_to_gguf.py /models/SomeModel-BF16 \
|
|
108
|
+
--outfile SomeModel-BF16.gguf --outtype bf16
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Python API
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from llm_dequant.model import convert, verify, inspect_checkpoint
|
|
115
|
+
from llm_dequant.nvfp4 import dequantize_nvfp4, unpack_fp4, pack_fp4
|
|
116
|
+
|
|
117
|
+
convert("/models/in-nvfp4", "/models/out-bf16", dtype="bf16")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## The NVFP4 format, in one table
|
|
121
|
+
|
|
122
|
+
`nvfp4-pack-quantized` (emitted by
|
|
123
|
+
[llm-compressor](https://github.com/vllm-project/llm-compressor)) stores, per
|
|
124
|
+
quantized Linear:
|
|
125
|
+
|
|
126
|
+
| tensor | dtype | shape | meaning |
|
|
127
|
+
|---|---|---|---|
|
|
128
|
+
| `weight_packed` | uint8 | `[m, n/2]` | two FP4-E2M1 codes per byte, low nibble first |
|
|
129
|
+
| `weight_scale` | fp8-e4m3 | `[m, n/16]` | one scale per group of 16 columns |
|
|
130
|
+
| `weight_global_scale` | fp32 | scalar | per-module global scale *(optional)* |
|
|
131
|
+
|
|
132
|
+
An FP4 code is 1 sign bit + 3 bits indexing the E2M1 magnitude table
|
|
133
|
+
`[0, 0.5, 1, 1.5, 2, 3, 4, 6]`, and
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
W[i, j] = e2m1(code[i, j]) · scale[i, j//16] / weight_global_scale
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Dequantization is exact.** Every recovered value sits precisely on the
|
|
140
|
+
scaled FP4 lattice (computed in fp32, cast once to the output dtype). Nothing
|
|
141
|
+
the NVFP4 checkpoint encodes is lost. What the original 4-bit quantization
|
|
142
|
+
already destroyed is of course not recoverable — the output is *dense*, not
|
|
143
|
+
*restored*. If you re-quantize the result (e.g. to GGUF), disclose the FP4
|
|
144
|
+
provenance: tiers at or below ~4 bpw lose essentially nothing, higher tiers
|
|
145
|
+
only improve the never-quantized tensors.
|
|
146
|
+
|
|
147
|
+
## How correctness is established
|
|
148
|
+
|
|
149
|
+
Two independent layers, both of which you can run yourself:
|
|
150
|
+
|
|
151
|
+
**1. `llm-dequant verify <src>` — against your checkpoint.**
|
|
152
|
+
Samples random packed modules, dequantizes, renormalizes by the effective
|
|
153
|
+
scale, re-packs with nearest-E2M1 rounding, and requires **byte equality**
|
|
154
|
+
with the original `weight_packed`. Any error in nibble order, scale layout,
|
|
155
|
+
group mapping, or global-scale handling breaks byte equality. (This proves
|
|
156
|
+
self-consistency against the real bytes; spec conformance comes from layer 2.)
|
|
157
|
+
|
|
158
|
+
**2. The test suite — against the reference implementation.**
|
|
159
|
+
Hand-computed vectors, exhaustive FP4 code tables, property-based round-trips,
|
|
160
|
+
end-to-end synthetic checkpoints (sharded + single-file, with/without global
|
|
161
|
+
scale), corruption and path-traversal rejection, and a bit-exactness test
|
|
162
|
+
against upstream `compressed-tensors` (runs in CI).
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
pip install -e .[dev] && pytest
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Scope
|
|
169
|
+
|
|
170
|
+
Supported: `format: nvfp4-pack-quantized`, symmetric, `group_size: 16` — the
|
|
171
|
+
only layout llm-compressor emits for NVFP4 today. Fused-MoE expert tensors
|
|
172
|
+
(`[experts, m, n/2]`) work unchanged.
|
|
173
|
+
|
|
174
|
+
Rejected loudly, never converted silently: other compressed-tensors formats,
|
|
175
|
+
asymmetric quantization (`weight_zero_point`), NaN/Inf scales, shard names
|
|
176
|
+
that escape the checkpoint directory, colliding output tensor names.
|
|
177
|
+
|
|
178
|
+
Dropped by design: activation-quantization metadata (`input_global_scale`) —
|
|
179
|
+
the output is dense; runtime activation quantization no longer applies.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
Apache-2.0. The FP4/E2M1 constant table follows the format specification
|
|
184
|
+
established by the vLLM / compressed-tensors projects (Apache-2.0).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
llm_dequant/__init__.py,sha256=1xGZt_Jg7IAkWy4SyF8Kq7pfOWhEw2Jalgl_1bT9Uqs,157
|
|
2
|
+
llm_dequant/cli.py,sha256=kUU0cmHpH9G7GAic3IxGiG8ZCZMFibYB-DGQxygbXAY,2581
|
|
3
|
+
llm_dequant/model.py,sha256=NkqE1y1NEVAYJjwWn1Eg2jQdlaupPHON1C6lObQfLRY,14617
|
|
4
|
+
llm_dequant/nvfp4.py,sha256=_6SPTCoTTuAElkD8jP-UJHsvYvYsSiEu81ulXfn5NWA,5691
|
|
5
|
+
llm_dequant-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
6
|
+
llm_dequant-0.1.0.dist-info/METADATA,sha256=de5XdLAP9KA_Zq6NYFwYS1mISwgzmPjDk7lwWxyF368,7266
|
|
7
|
+
llm_dequant-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
8
|
+
llm_dequant-0.1.0.dist-info/entry_points.txt,sha256=4nG4sTJQV5B8Rc7xYHRiSs10XJYOzq_oDU01XNHruDQ,53
|
|
9
|
+
llm_dequant-0.1.0.dist-info/top_level.txt,sha256=MJnOjCTdhtQvvSQGuAYjx54I8nNTeSOY-cjcrPYNhH0,12
|
|
10
|
+
llm_dequant-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
llm_dequant
|