EmbeddingGemma's quantization-aware training produces three variants: int4 per-block, int8 per-block, and a mixed scheme that stores the embedding table, the feed-forward blocks and the output projection in int4 while keeping the attention projections in int8. Implement the byte accounting, including the per-block scales that pure "bits per weight" numbers leave out.
bytes_per_param(precision)
"fp32" is 4, "bf16" and "fp16" are 2, "int8" is 1, "int4" is 0.5. Unknown precisions raise ValueError.layer_bytes(n_params, precision, block=None, scale_bytes=2)
n_params * bytes_per_param(precision), plus one scale of scale_bytes per block of block parameters (ceil(n_params / block) scales) when block is given and the precision is int8 or int4. Return a float.model_footprint_mb(layers, scheme, block=None, scale_bytes=2)
layers is a list of (name, kind, n_params) and scheme maps each kind to a precision (a plain string applies one precision to every layer). Return the total in megabytes (10^6 bytes) rounded to 2 decimals.effective_bits(precision, block=None, scale_bytes=2)
8 * bytes_per_param + 8 * scale_bytes / block (the scale term only when block is given and the precision is an integer type). Rounded to 3 decimals.fits(weights_mb, activations_mb, budget_mb)
True when weights_mb + activations_mb <= budget_mb.math.ceil(n_params / block) counts the scales; a partial block still needs one.