def forward_matcher(xlinear_model, X, **kwargs):
    """Forward through the matcher to get the leaf id.
    
    Args:
        xlinear_model: The input xlinear model.
        X: Input feature matrix.
        kwargs: The config.
    
    Returns:
        The matching matrix.
    """
    csr_codes = None
    model_chain = xlinear_model.model.model_chain
    for layer_id in range(len(model_chain) - 1):
        cur_model = model_chain[layer_id]
        level_pred = cur_model.predict(
            X,
            csr_codes=csr_codes,
            only_topk=kwargs["beam_size"],
            post_processor=kwargs["post_processor"],
        )
        csr_codes = level_pred
    return csr_codes