MCPcopy Create free account
hub / github.com/antirez/ds4 / parse_args

Function parse_args

gguf-tools/deepseek4-quantize.c:1740–1814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1738 const uint8_t value = v ? 1u : 0u;
1739 if (fwrite(&value, sizeof(value), 1, fp) != 1) die("write bool failed");
1740}
1741
1742static void write_gguf_string(FILE *fp, const char *s) {
1743 uint64_t n = strlen(s);
1744 write_u64(fp, n);
1745 if (n && fwrite(s, 1, (size_t)n, fp) != (size_t)n) die("write string failed");
1746}
1747
1748static bool is_imatrix_kv_key(const char *key) {
1749 return str_starts(key, "quantize.imatrix.");
1750}
1751
1752static size_t extra_imatrix_kv_size(const imatrix_store *im) {
1753 if (!imatrix_enabled(im)) return 0;
1754 size_t n = 0;
1755 n += gguf_string_size(DS4_KV_QUANTIZE_IMATRIX_FILE) + 4 + gguf_string_size(im->file);
1756 n += gguf_string_size(DS4_KV_QUANTIZE_IMATRIX_N_ENTRIES) + 4 + 8;
1757 if (im->dataset) n += gguf_string_size(DS4_KV_QUANTIZE_IMATRIX_DATASET) + 4 + gguf_string_size(im->dataset);
1758 if (im->chunks > 0) n += gguf_string_size(DS4_KV_QUANTIZE_IMATRIX_N_CHUNKS) + 4 + 8;
1759 return n;
1760}
1761
1762static uint64_t extra_imatrix_kv_count(const imatrix_store *im) {
1763 if (!imatrix_enabled(im)) return 0;
1764 return 2 + (im->dataset ? 1 : 0) + (im->chunks > 0 ? 1 : 0);
1765}
1766
1767static void write_imatrix_kvs(FILE *fp, const imatrix_store *im) {
1768 if (!imatrix_enabled(im)) return;
1769 write_gguf_string(fp, DS4_KV_QUANTIZE_IMATRIX_FILE);
1770 write_u32(fp, GGUF_TYPE_STRING);
1771 write_gguf_string(fp, im->file);
1772
1773 write_gguf_string(fp, DS4_KV_QUANTIZE_IMATRIX_N_ENTRIES);
1774 write_u32(fp, GGUF_TYPE_UINT64);
1775 write_u64(fp, (uint64_t)im->n_entries);
1776
1777 if (im->dataset) {
1778 write_gguf_string(fp, DS4_KV_QUANTIZE_IMATRIX_DATASET);
1779 write_u32(fp, GGUF_TYPE_STRING);
1780 write_gguf_string(fp, im->dataset);
1781 }
1782 if (im->chunks > 0) {
1783 write_gguf_string(fp, DS4_KV_QUANTIZE_IMATRIX_N_CHUNKS);
1784 write_u32(fp, GGUF_TYPE_UINT64);
1785 write_u64(fp, (uint64_t)im->chunks);
1786 }
1787}
1788
1789static gguf_file load_gguf_metadata_with_override(const char *path,
1790 const hf_model_metadata *metadata) {
1791 gguf_file g = {0};
1792 g.path = xstrdup(path);
1793 FILE *fp = fopen(path, "rb");
1794 if (!fp) die_errno("open GGUF", path);
1795 char magic[4];
1796 if (fread(magic, 1, sizeof(magic), fp) != sizeof(magic) || memcmp(magic, "GGUF", 4) != 0) {
1797 die("bad GGUF template");

Callers 1

mainFunction · 0.85

Calls 7

need_valueFunction · 0.85
parse_typeFunction · 0.85
file_existsFunction · 0.85
usageFunction · 0.70
dieFunction · 0.70
xreallocFunction · 0.70
xstrdupFunction · 0.70

Tested by

no test coverage detected