﻿# Kolors ChatGLM conditions: sequence features and pooled features use different selections

Preserve Kolors ChatGLM hidden-layer selection, sequence-first axis conversion, and pooled features when implementing custom text conditioning or batched inference.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-kolors-chatglm-sequence-pooled-axis-contract/
Language: en

## Identify the selected text encoder

The [Kolors pipeline documentation](https://huggingface.co/docs/diffusers/api/pipelines/kolors) identifies ChatGLM as its frozen text encoder. A generic image-generation integration must not assume the encoder follows every convention of a CLIP-based pipeline. The model consumes particular text representations learned together with its generator interface. Preserving tokenizer identity and supported sequence handling is necessary, but it is not sufficient if a custom implementation selects a different hidden layer or constructs a different pooled condition.

## Trace token-level features

The [pipeline implementation](https://raw.githubusercontent.com/huggingface/diffusers/main/src/diffusers/pipelines/kolors/pipeline_kolors.py) selects the penultimate hidden-state output for token-level conditioning. That output initially uses sequence, batch, hidden axes and is permuted into batch, sequence, hidden order. A reshape is not a semantic substitute for an axis permutation: it can retain storage values while associating them with the wrong examples or token positions. Keep the actual axis transformation explicit when porting the encoder or exporting its outputs.

## Preserve the distinct pooled selection

The same implementation constructs pooled features from the final position of the final hidden-state output. This differs from averaging the penultimate token features. The pooled and sequence conditions therefore have separate provenance even though both originate in one text encoder. Cache and validate them together without synthesizing one from the other through an undocumented reduction. Matching the expected pooled shape only proves dimensional compatibility, not that the generator received the representation it was trained to interpret.

## Use a batch that reveals alignment errors

Imagine a custom worker tested only with a single short prompt. A mistaken sequence/batch conversion may be harder to notice there than with several clearly different prompts and lengths. Compare each example's token features and pooled vector with the native path before evaluating full images. The [official Kolors repository](https://github.com/Kwai-Kolors/Kolors) provides model and usage context, including bilingual input support, but that support does not repair a wrapper that swaps examples or changes the hidden-state selection.

## Keep conditioning provenance complete

Record text-encoder and tokenizer revisions, hidden-state selections, axis transformations, masks or position inputs where used, and paired negative conditions. Validate both feature types before optimizing text caching. Existing guides on [tensor axes](/journal/tensor-axes-batch-sequence-hidden/) and [strides versus transpose](/journal/tensor-strides-transpose-contiguous/) provide background. Kolors' distinctive boundary is a specific ChatGLM feature extraction contract; correct shapes and fluent input text alone cannot prove that custom conditioning preserved it.
