Files
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

40 lines
2.3 KiB
C++

// include/strata/image/te_dequant.hpp - the text encoder's weight decoders: GGUF block formats -> f16 rows, on CUDA and
// HIP (src/image/te/te_dequant.cu) and on the host (the same bits, for tests).
//
// Qwen-Image-2.1's text encoder (Qwen3-VL-8B, Unsloth UD-Q4_K_XL) stores its layer weights as Q4_K, Q5_K, Q6_K and
// IQ4_XS; the 1-D weights are F32. Our encoder decodes one matrix at a time into an f16 buffer and multiplies it with
// cuBLAS / hipBLAS GemmEx. The value of every weight is the one ggml's dequantize_row_* computes in f32 (the order of
// operations of include/strata/artifact/dequant.hpp, every product and difference rounded on its own, never fused),
// rounded to f16 to nearest even (include/strata/kernels/f16_bits.hpp). The device and the host path give the same
// bits; tools/image/te test program te_dequant_check compares them over every tensor of a file.
//
// Kept separate from the engine's src/kernels/cuda/dequant_bf16.cu on purpose (coordinator 11-11): sharing one header
// of block decoders with the engine is a later step under the engine identity gate.
#pragma once
#include <cstddef>
#include <cstdint>
#include <string>
namespace strata::image {
// ggml type ids the decoders read
enum : uint32_t { TE_F32 = 0, TE_F16 = 1, TE_Q8_0 = 8, TE_Q4_K = 12, TE_Q5_K = 13, TE_Q6_K = 14, TE_IQ4_XS = 23, TE_BF16 = 30 };
bool te_type_supported(uint32_t type);
// Bytes of one row of ne0 values; 0 when the type is not supported or ne0 is not a whole number of blocks.
size_t te_row_bytes(uint32_t type, int64_t ne0);
// rows x ne0 values (GGUF layout, rows one after the other) at d_src -> f16 bit patterns at d_dst, row-major (ld =
// ne0), on `stream` (a cudaStream_t / hipStream_t; nullptr = the default stream). Asynchronous; "" on success.
std::string te_dequant_f16(uint32_t type, const void* d_src, int64_t ne0, int64_t rows, uint16_t* d_dst, void* stream);
// The same on the host (the reference of the device path).
std::string te_dequant_f16_host(uint32_t type, const uint8_t* src, int64_t ne0, int64_t rows, uint16_t* dst);
// The f32 values themselves on the host (ggml_get_rows of the token embedding: no f16 rounding).
std::string te_dequant_f32_host(uint32_t type, const uint8_t* src, int64_t ne0, int64_t rows, float* dst);
} // namespace strata::image