Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/int8_convrot.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A supported configuration has this form:
}
```

The convrot group size must be a power of four and must divide the input feature dimension. The commonly used configuration is H256, with `convrot_groupsize` set to `256`.
When `convrot` is enabled, `convrot_groupsize` defaults to `256` (H256). The group size must be a power of four no greater than `256` and must divide the input feature dimension.

## How INT8 convrot works

Expand Down
37 changes: 11 additions & 26 deletions src/model/diffusion/ltxv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,19 @@ namespace LTXV {
int64_t a_dim;
bool cross_attention_adaln;

void init_params(ggml_context* ctx,
const String2TensorStorage& tensor_storage_map = {},
const std::string prefix = "") override {
void init_params(ggml_context* ctx, const String2TensorStorage& = {}, const std::string = "") override {
// The tables determine the type of the modulation values applied to F32 activations.
int64_t coeff = cross_attention_adaln ? 9 : 6;
ggml_type vw = get_type(prefix + "scale_shift_table", tensor_storage_map, GGML_TYPE_F32);
ggml_type aw = get_type(prefix + "audio_scale_shift_table", tensor_storage_map, GGML_TYPE_F32);
params["scale_shift_table"] = ggml_new_tensor_2d(ctx, vw, v_dim, coeff);
params["audio_scale_shift_table"] = ggml_new_tensor_2d(ctx, aw, a_dim, coeff);
params["scale_shift_table"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, v_dim, coeff);
params["audio_scale_shift_table"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, a_dim, coeff);

if (cross_attention_adaln) {
ggml_type vpw = get_type(prefix + "prompt_scale_shift_table", tensor_storage_map, GGML_TYPE_F32);
ggml_type apw = get_type(prefix + "audio_prompt_scale_shift_table", tensor_storage_map, GGML_TYPE_F32);
params["prompt_scale_shift_table"] = ggml_new_tensor_2d(ctx, vpw, v_dim, 2);
params["audio_prompt_scale_shift_table"] = ggml_new_tensor_2d(ctx, apw, a_dim, 2);
params["prompt_scale_shift_table"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, v_dim, 2);
params["audio_prompt_scale_shift_table"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, a_dim, 2);
}

ggml_type avw = get_type(prefix + "scale_shift_table_a2v_ca_audio", tensor_storage_map, GGML_TYPE_F32);
ggml_type vaw = get_type(prefix + "scale_shift_table_a2v_ca_video", tensor_storage_map, GGML_TYPE_F32);
params["scale_shift_table_a2v_ca_audio"] = ggml_new_tensor_2d(ctx, avw, a_dim, 5);
params["scale_shift_table_a2v_ca_video"] = ggml_new_tensor_2d(ctx, vaw, v_dim, 5);
params["scale_shift_table_a2v_ca_audio"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, a_dim, 5);
params["scale_shift_table_a2v_ca_video"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, v_dim, 5);
}

BasicAVTransformerBlock(int64_t v_dim,
Expand Down Expand Up @@ -768,17 +761,9 @@ namespace LTXV {
struct LTXAVModelBlock : public GGMLBlock {
LTXAVConfig config;

void init_params(ggml_context* ctx,
const String2TensorStorage& tensor_storage_map = {},
const std::string prefix = "") override {
params["scale_shift_table"] = ggml_new_tensor_2d(ctx,
get_type(prefix + "scale_shift_table", tensor_storage_map, GGML_TYPE_F32),
config.hidden_size,
2);
params["audio_scale_shift_table"] = ggml_new_tensor_2d(ctx,
get_type(prefix + "audio_scale_shift_table", tensor_storage_map, GGML_TYPE_F32),
config.audio_hidden_size,
2);
void init_params(ggml_context* ctx, const String2TensorStorage& = {}, const std::string = "") override {
params["scale_shift_table"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, config.hidden_size, 2);
params["audio_scale_shift_table"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, config.audio_hidden_size, 2);
if (config.use_keyframes_abs_pos_embedding) {
// Added to f32 activations, and backends without BF16 support (e.g. Vulkan on RADV) can't add a BF16 tensor.
params["keyframes_abs_pos_embedding"] = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, config.hidden_size, 1);
Expand Down
7 changes: 3 additions & 4 deletions src/model_io/safetensors_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ static bool read_comfy_quant_config(std::ifstream& file,
const nlohmann::json json = nlohmann::json::parse(data.data(), data.data() + size);
config.format = json.value("format", "");
config.convrot = json.value("convrot", false);
config.group_size = json.value("convrot_groupsize", 0);
config.weight_group_size = json.value("group_size", 0);
if (config.format == "convrot_w4a4" || config.format == "asym_w4a8_int8") {
// Packed W4 formats imply rotation, including exports without the INT8 convrot flag.
config.convrot = true;
config.group_size = json.value("convrot_groupsize", 256);
config.convrot = true;
}
config.group_size = json.value("convrot_groupsize", config.convrot ? 256 : 0);
config.weight_group_size = json.value("group_size", 0);
if (config.format == "asym_w4a8_int8") {
// ComfyUI defaults the W4A8 weight group size to 16 when the key is missing.
config.weight_group_size = json.value("group_size", 16);
Expand Down
Loading