



'''simple docstring'''





import argparse
import json
from collections import OrderedDict
from pathlib import Path

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import (
    SegformerConfig,
    SegformerForImageClassification,
    SegformerForSemanticSegmentation,
    SegformerImageProcessor,
)
from transformers.utils import logging


logging.set_verbosity_info()
SCREAMING_SNAKE_CASE__          =  logging.get_logger(__name__)




def 							lowerCamelCase	(					_snake_case	:    List[Any]  ,_snake_case	:    Tuple=False							):





    '''simple docstring'''


    lowercase__									=    OrderedDict()
    for key, value in state_dict.items():
        if encoder_only and not key.startswith("head"							):
            lowercase__									=    "segformer.encoder." + key
        if key.startswith("backbone"							):
            lowercase__									=    key.replace("backbone"  ,"segformer.encoder"							)
        if "patch_embed" in key:
            # replace for example patch_embed1 by patch_embeddings.0
            lowercase__									=    key[key.find("patch_embed"							) + len("patch_embed"							)]
            lowercase__									=    key.replace(f'''patch_embed{idx}'''  ,f'''patch_embeddings.{int(_snake_case							)-1}'''							)
        if "norm" in key:
            lowercase__									=    key.replace("norm"  ,"layer_norm"							)
        if "segformer.encoder.layer_norm" in key:
            # replace for example layer_norm1 by layer_norm.0
            lowercase__									=    key[key.find("segformer.encoder.layer_norm"							) + len("segformer.encoder.layer_norm"							)]
            lowercase__									=    key.replace(f'''layer_norm{idx}'''  ,f'''layer_norm.{int(_snake_case							)-1}'''							)
        if "layer_norm1" in key:
            lowercase__									=    key.replace("layer_norm1"  ,"layer_norm_1"							)
        if "layer_norm2" in key:
            lowercase__									=    key.replace("layer_norm2"  ,"layer_norm_2"							)
        if "block" in key:
            # replace for example block1 by block.0
            lowercase__									=    key[key.find("block"							) + len("block"							)]
            lowercase__									=    key.replace(f'''block{idx}'''  ,f'''block.{int(_snake_case							)-1}'''							)
        if "attn.q" in key:
            lowercase__									=    key.replace("attn.q"  ,"attention.self.query"							)
        if "attn.proj" in key:
            lowercase__									=    key.replace("attn.proj"  ,"attention.output.dense"							)
        if "attn" in key:
            lowercase__									=    key.replace("attn"  ,"attention.self"							)
        if "fc1" in key:
            lowercase__									=    key.replace("fc1"  ,"dense1"							)
        if "fc2" in key:
            lowercase__									=    key.replace("fc2"  ,"dense2"							)
        if "linear_pred" in key:
            lowercase__									=    key.replace("linear_pred"  ,"classifier"							)
        if "linear_fuse" in key:
            lowercase__									=    key.replace("linear_fuse.conv"  ,"linear_fuse"							)
            lowercase__									=    key.replace("linear_fuse.bn"  ,"batch_norm"							)
        if "linear_c" in key:
            # replace for example linear_c4 by linear_c.3
            lowercase__									=    key[key.find("linear_c"							) + len("linear_c"							)]
            lowercase__									=    key.replace(f'''linear_c{idx}'''  ,f'''linear_c.{int(_snake_case							)-1}'''							)
        if key.startswith("head"							):
            lowercase__									=    key.replace("head"  ,"classifier"							)
        lowercase__									=    value

    return new_state_dict




def 							lowerCamelCase	(					_snake_case	:    List[str]  ,_snake_case	:    Optional[int]							):





    '''simple docstring'''


    for i in range(config.num_encoder_blocks							):
        for j in range(config.depths[i]							):
            # read in weights + bias of keys and values (which is a single matrix in the original implementation)
            lowercase__									=    state_dict.pop(f'''segformer.encoder.block.{i}.{j}.attention.self.kv.weight'''							)
            lowercase__									=    state_dict.pop(f'''segformer.encoder.block.{i}.{j}.attention.self.kv.bias'''							)
            # next, add keys and values (in that order) to the state dict
            lowercase__									=    kv_weight[
                : config.hidden_sizes[i], :
            ]
            lowercase__									=    kv_bias[: config.hidden_sizes[i]]
            lowercase__									=    kv_weight[
                config.hidden_sizes[i] :, :
            ]
            lowercase__									=    kv_bias[
                config.hidden_sizes[i] :
            ]




def 							lowerCamelCase	(					):





    '''simple docstring'''


    lowercase__									=    "http://images.cocodataset.org/val2017/000000039769.jpg"
    lowercase__									=    Image.open(requests.get(_snake_case  ,stream=_snake_case							).raw							)

    return image




@torch.no_grad()
def 							lowerCamelCase	(					_snake_case	:    Optional[int]  ,_snake_case	:    Dict  ,_snake_case	:    Optional[int]							):





    '''simple docstring'''


    lowercase__									=    SegformerConfig()
    lowercase__									=    False

    # set attributes based on model_name
    lowercase__									=    "huggingface/label-files"
    if "segformer" in model_name:
        lowercase__									=    model_name[len("segformer."							) : len("segformer."							) + 2]
        if "ade" in model_name:
            lowercase__									=    150
            lowercase__									=    "ade20k-id2label.json"
            lowercase__									=    (1, 150, 128, 128)
        elif "city" in model_name:
            lowercase__									=    19
            lowercase__									=    "cityscapes-id2label.json"
            lowercase__									=    (1, 19, 128, 128)
        else:
            raise ValueError(f'''Model {model_name} not supported'''							)
    elif "mit" in model_name:
        lowercase__									=    True
        lowercase__									=    model_name[4:6]
        lowercase__									=    1_000
        lowercase__									=    "imagenet-1k-id2label.json"
        lowercase__									=    (1, 1_000)
    else:
        raise ValueError(f'''Model {model_name} not supported'''							)

    # set config attributes
    lowercase__									=    json.load(open(hf_hub_download(_snake_case  ,_snake_case  ,repo_type="dataset"							)  ,"r"							)							)
    lowercase__									=    {int(_snake_case							): v for k, v in idalabel.items()}
    lowercase__									=    idalabel
    lowercase__									=    {v: k for k, v in idalabel.items()}
    if size == "b0":
        pass
    elif size == "b1":
        lowercase__									=    [64, 128, 320, 512]
        lowercase__									=    256
    elif size == "b2":
        lowercase__									=    [64, 128, 320, 512]
        lowercase__									=    768
        lowercase__									=    [3, 4, 6, 3]
    elif size == "b3":
        lowercase__									=    [64, 128, 320, 512]
        lowercase__									=    768
        lowercase__									=    [3, 4, 18, 3]
    elif size == "b4":
        lowercase__									=    [64, 128, 320, 512]
        lowercase__									=    768
        lowercase__									=    [3, 8, 27, 3]
    elif size == "b5":
        lowercase__									=    [64, 128, 320, 512]
        lowercase__									=    768
        lowercase__									=    [3, 6, 40, 3]
    else:
        raise ValueError(f'''Size {size} not supported'''							)

    # load image processor (only resize + normalize)
    lowercase__									=    SegformerImageProcessor(
        image_scale=(512, 512)  ,keep_ratio=_snake_case  ,align=_snake_case  ,do_random_crop=_snake_case							)

    # prepare image
    lowercase__									=    prepare_img()
    lowercase__									=    image_processor(images=_snake_case  ,return_tensors="pt"							).pixel_values

    logger.info(f'''Converting model {model_name}...'''							)

    # load original state dict
    if encoder_only:
        lowercase__									=    torch.load(_snake_case  ,map_location=torch.device("cpu"							)							)
    else:
        lowercase__									=    torch.load(_snake_case  ,map_location=torch.device("cpu"							)							)["state_dict"]

    # rename keys
    lowercase__									=    rename_keys(_snake_case  ,encoder_only=_snake_case							)
    if not encoder_only:
        del state_dict["decode_head.conv_seg.weight"]
        del state_dict["decode_head.conv_seg.bias"]

    # key and value matrices need special treatment
    read_in_k_v(_snake_case  ,_snake_case							)

    # create HuggingFace model and load state dict
    if encoder_only:
        lowercase__									=    False
        lowercase__									=    SegformerForImageClassification(_snake_case							)
    else:
        lowercase__									=    SegformerForSemanticSegmentation(_snake_case							)
    model.load_state_dict(_snake_case							)
    model.eval()

    # forward pass
    lowercase__									=    model(_snake_case							)
    lowercase__									=    outputs.logits

    # set expected_slice based on model name
    # ADE20k checkpoints
    if model_name == "segformer.b0.512x512.ade.160k":
        lowercase__									=    torch.tensor(
            [
                [[-4.6_310, -5.5_232, -6.2_356], [-5.1_921, -6.1_444, -6.5_996], [-5.4_424, -6.2_790, -6.7_574]],
                [[-12.1_391, -13.3_122, -13.9_554], [-12.8_732, -13.9_352, -14.3_563], [-12.9_438, -13.8_226, -14.2_513]],
                [[-12.5_134, -13.4_686, -14.4_915], [-12.8_669, -14.4_343, -14.7_758], [-13.2_523, -14.5_819, -15.0_694]],
            ]							)
    elif model_name == "segformer.b1.512x512.ade.160k":
        lowercase__									=    torch.tensor(
            [
                [[-7.5_820, -8.7_231, -8.3_215], [-8.0_600, -10.3_529, -10.0_304], [-7.5_208, -9.4_103, -9.6_239]],
                [[-12.6_918, -13.8_994, -13.7_137], [-13.3_196, -15.7_523, -15.4_789], [-12.9_343, -14.8_757, -14.9_689]],
                [[-11.1_911, -11.9_421, -11.3_243], [-11.3_342, -13.6_839, -13.3_581], [-10.3_909, -12.1_832, -12.4_858]],
            ]							)
    elif model_name == "segformer.b2.512x512.ade.160k":
        lowercase__									=    torch.tensor(
            [
                [[-11.8_173, -14.3_850, -16.3_128], [-14.5_648, -16.5_804, -18.6_568], [-14.7_223, -15.7_387, -18.4_218]],
                [[-15.7_290, -17.9_171, -19.4_423], [-18.3_105, -19.9_448, -21.4_661], [-17.9_296, -18.6_497, -20.7_910]],
                [[-15.0_783, -17.0_336, -18.2_789], [-16.8_771, -18.6_870, -20.1_612], [-16.2_454, -17.1_426, -19.5_055]],
            ]							)
    elif model_name == "segformer.b3.512x512.ade.160k":
        lowercase__									=    torch.tensor(
            [
                [[-9.0_878, -10.2_081, -10.1_891], [-9.3_144, -10.7_941, -10.9_843], [-9.2_294, -10.3_855, -10.5_704]],
                [[-12.2_316, -13.9_068, -13.6_102], [-12.9_161, -14.3_702, -14.3_235], [-12.5_233, -13.7_174, -13.7_932]],
                [[-14.6_275, -15.2_490, -14.9_727], [-14.3_400, -15.9_687, -16.2_827], [-14.1_484, -15.4_033, -15.8_937]],
            ]							)
    elif model_name == "segformer.b4.512x512.ade.160k":
        lowercase__									=    torch.tensor(
            [
                [[-12.3_144, -13.2_447, -14.0_802], [-13.3_614, -14.5_816, -15.6_117], [-13.3_340, -14.4_433, -16.2_219]],
                [[-19.2_781, -20.4_128, -20.7_506], [-20.6_153, -21.6_566, -22.0_998], [-19.9_800, -21.0_430, -22.1_494]],
                [[-18.8_739, -19.7_804, -21.1_834], [-20.1_233, -21.6_765, -23.2_944], [-20.0_315, -21.2_641, -23.6_944]],
            ]							)
    elif model_name == "segformer.b5.640x640.ade.160k":
        lowercase__									=    torch.tensor(
            [
                [[-9.5_524, -12.0_835, -11.7_348], [-10.5_229, -13.6_446, -14.5_662], [-9.5_842, -12.8_851, -13.9_414]],
                [[-15.3_432, -17.5_323, -17.0_818], [-16.3_330, -18.9_255, -19.2_101], [-15.1_340, -17.7_848, -18.3_971]],
                [[-12.6_072, -14.9_486, -14.6_631], [-13.7_629, -17.0_907, -17.7_745], [-12.7_899, -16.1_695, -17.1_671]],
            ]							)
    # Cityscapes checkpoints
    elif model_name == "segformer.b0.1024x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-11.9_295, -13.4_057, -14.8_106], [-13.3_431, -14.8_179, -15.3_781], [-14.2_836, -15.5_942, -16.1_588]],
                [[-11.4_906, -12.8_067, -13.6_564], [-13.1_189, -14.0_500, -14.1_543], [-13.8_748, -14.5_136, -14.8_789]],
                [[0.5_374, 0.1_067, -0.4_742], [0.1_141, -0.2_255, -0.7_099], [-0.3_000, -0.5_924, -1.3_105]],
            ]							)
    elif model_name == "segformer.b0.512x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-7.8_217, -9.8_767, -10.1_717], [-9.4_438, -10.9_058, -11.4_047], [-9.7_939, -12.3_495, -12.1_079]],
                [[-7.1_514, -9.5_336, -10.0_860], [-9.7_776, -11.6_822, -11.8_439], [-10.1_411, -12.7_655, -12.8_972]],
                [[0.3_021, 0.0_805, -0.2_310], [-0.0_328, -0.1_605, -0.2_714], [-0.1_408, -0.5_477, -0.6_976]],
            ]							)
    elif model_name == "segformer.b0.640x1280.city.160k":
        lowercase__									=    torch.tensor(
            [
                [
                    [-1.1_3_7_2e0_1, -1.2_7_8_7e0_1, -1.3_4_7_7e0_1],
                    [-1.2_5_3_6e0_1, -1.4_1_9_4e0_1, -1.4_4_0_9e0_1],
                    [-1.3_2_1_7e0_1, -1.4_8_8_8e0_1, -1.5_3_2_7e0_1],
                ],
                [
                    [-1.4_7_9_1e0_1, -1.7_1_2_2e0_1, -1.8_2_7_7e0_1],
                    [-1.7_1_6_3e0_1, -1.9_1_9_2e0_1, -1.9_5_3_3e0_1],
                    [-1.7_8_9_7e0_1, -1.9_9_9_1e0_1, -2.0_3_1_5e0_1],
                ],
                [
                    [7.6_7_2_3e-0_1, 4.1_9_2_1e-0_1, -7.7_8_7_8e-0_2],
                    [4.7_7_7_2e-0_1, 9.5_5_5_7e-0_3, -2.8_0_8_2e-0_1],
                    [3.6_0_3_2e-0_1, -2.4_8_2_6e-0_1, -5.1_1_6_8e-0_1],
                ],
            ]							)
    elif model_name == "segformer.b0.768x768.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-9.4_959, -11.3_087, -11.7_479], [-11.0_025, -12.6_540, -12.3_319], [-11.4_064, -13.0_487, -12.9_905]],
                [[-9.8_905, -11.3_084, -12.0_854], [-11.1_726, -12.7_698, -12.9_583], [-11.5_985, -13.3_278, -14.1_774]],
                [[0.2_213, 0.0_192, -0.2_466], [-0.1_731, -0.4_213, -0.4_874], [-0.3_126, -0.6_541, -1.1_389]],
            ]							)
    elif model_name == "segformer.b1.1024x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-13.5_748, -13.9_111, -12.6_500], [-14.3_500, -15.3_683, -14.2_328], [-14.7_532, -16.0_424, -15.6_087]],
                [[-17.1_651, -15.8_725, -12.9_653], [-17.2_580, -17.3_718, -14.8_223], [-16.6_058, -16.8_783, -16.7_452]],
                [[-3.6_456, -3.0_209, -1.4_203], [-3.0_797, -3.1_959, -2.0_000], [-1.8_757, -1.9_217, -1.6_997]],
            ]							)
    elif model_name == "segformer.b2.1024x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-16.0_976, -16.4_856, -17.3_962], [-16.6_234, -19.0_342, -19.7_685], [-16.0_900, -18.0_661, -19.1_180]],
                [[-18.4_750, -18.8_488, -19.5_074], [-19.4_030, -22.1_570, -22.5_977], [-19.1_191, -20.8_486, -22.3_783]],
                [[-4.5_178, -5.5_037, -6.5_109], [-5.0_884, -7.2_174, -8.0_334], [-4.4_156, -5.8_117, -7.2_970]],
            ]							)
    elif model_name == "segformer.b3.1024x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-14.2_081, -14.4_732, -14.1_977], [-14.5_867, -16.4_423, -16.6_356], [-13.4_441, -14.9_685, -16.8_696]],
                [[-14.4_576, -14.7_073, -15.0_451], [-15.0_816, -17.6_237, -17.9_873], [-14.4_213, -16.0_199, -18.5_992]],
                [[-4.7_349, -4.9_588, -5.0_966], [-4.3_210, -6.9_325, -7.2_591], [-3.4_312, -4.7_484, -7.1_917]],
            ]							)
    elif model_name == "segformer.b4.1024x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-11.7_737, -11.9_526, -11.3_273], [-13.6_692, -14.4_574, -13.8_878], [-13.8_937, -14.6_924, -15.9_345]],
                [[-14.6_706, -14.5_330, -14.1_306], [-16.1_502, -16.8_180, -16.4_269], [-16.8_338, -17.8_939, -20.1_746]],
                [[1.0_491, 0.8_289, 1.0_310], [1.1_044, 0.5_219, 0.8_055], [1.0_899, 0.6_926, 0.5_590]],
            ]							)
    elif model_name == "segformer.b5.1024x1024.city.160k":
        lowercase__									=    torch.tensor(
            [
                [[-12.5_641, -13.4_777, -13.0_684], [-13.9_587, -15.8_983, -16.6_557], [-13.3_109, -15.7_350, -16.3_141]],
                [[-14.7_074, -15.4_352, -14.5_944], [-16.6_353, -18.1_663, -18.6_120], [-15.1_702, -18.0_329, -18.1_547]],
                [[-1.7_990, -2.0_951, -1.7_784], [-2.6_397, -3.8_245, -3.9_686], [-1.5_264, -2.8_126, -2.9_316]],
            ]							)
    else:
        lowercase__									=    logits.argmax(-1							).item()
        print("Predicted class:"  ,model.config.idalabel[predicted_class_idx]							)

    # verify logits
    if not encoder_only:
        assert logits.shape == expected_shape
        assert torch.allclose(logits[0, :3, :3, :3]  ,_snake_case  ,atol=1e-2							)

    # finally, save model and image processor
    logger.info(f'''Saving PyTorch model and image processor to {pytorch_dump_folder_path}...'''							)
    Path(_snake_case							).mkdir(exist_ok=_snake_case							)
    model.save_pretrained(_snake_case							)
    image_processor.save_pretrained(_snake_case							)


if __name__ == "__main__":
 SCREAMING_SNAKE_CASE__          =  argparse.ArgumentParser()

 parser.add_argument(
     "--model_name",
     default="segformer.b0.512x512.ade.160k",
     type=str,
     help="Name of the model you'd like to convert.",
 )
 parser.add_argument(
     "--checkpoint_path", default=None, type=str, help="Path to the original PyTorch checkpoint (.pth file)."
 )
 parser.add_argument(
     "--pytorch_dump_folder_path", default=None, type=str, help="Path to the folder to output PyTorch model."
 )
 SCREAMING_SNAKE_CASE__          =  parser.parse_args()
 convert_segformer_checkpoint(args.model_name, args.checkpoint_path, args.pytorch_dump_folder_path)









'''simple docstring'''





import unittest

from transformers import JukeboxTokenizer
from transformers.testing_utils import require_torch


class 					snake_case			(unittest.TestCase ):
       lowerCAmelCase__	:Dict     =       JukeboxTokenizer
       lowerCAmelCase__	:List[str]     =       {
           "artist": "Zac Brown Band",
           "genres": "Country",
           "lyrics": "I met a traveller from an antique land,\n        Who said \"Two vast and trunkless legs of stone\n        Stand in the desert. . . . Near them, on the sand,\n        Half sunk a shattered visage lies, whose frown,\n        And wrinkled lip, and sneer of cold command,\n        Tell that its sculptor well those passions read\n        Which yet survive, stamped on these lifeless things,\n        The hand that mocked them, and the heart that fed;\n        And on the pedestal, these words appear:\n        My name is Ozymandias, King of Kings;\n        Look on my Works, ye Mighty, and despair!\n        Nothing beside remains. Round the decay\n        Of that colossal Wreck, boundless and bare\n        The lone and level sands stretch far away\n        ",
       }



       @require_torch
       def 				_a   (					self   )	->				Dict:
           import torch

           lowercase__									=    JukeboxTokenizer.from_pretrained("openai/jukebox-1b-lyrics"   )
           lowercase__									=    tokenizer(**self.metas   )["input_ids"]
           # fmt: off
           lowercase__									=    [
               torch.tensor([[
                   0, 0, 0, 7_169, 507, 9, 76, 39, 31, 46, 76, 27,
                   76, 46, 44, 27, 48, 31, 38, 38, 31, 44, 76, 32,
                   44, 41, 39, 76, 27, 40, 76, 27, 40, 46, 35, 43,
                   47, 31, 76, 38, 27, 40, 30, 64, 78, 76, 76, 76,
                   76, 76, 76, 76, 76, 23, 34, 41, 76, 45, 27, 35,
                   30, 76, 71, 20, 49, 41, 76, 48, 27, 45, 46, 76,
                   27, 40, 30, 76, 46, 44, 47, 40, 37, 38, 31, 45,
                   45, 76, 38, 31, 33, 45, 76, 41, 32, 76, 45, 46,
                   41, 40, 31, 78, 76, 76, 76, 76, 76, 76, 76, 76,
                   19, 46, 27, 40, 30, 76, 35, 40, 76, 46, 34, 31,
                   76, 30, 31, 45, 31, 44, 46, 63, 76, 63, 76, 63,
                   76, 63, 76, 14, 31, 27, 44, 76, 46, 34, 31, 39,
                   64, 76, 41, 40, 76, 46, 34, 31, 76, 45, 27, 40,
                   30, 64, 78, 76, 76, 76, 76, 76, 76, 76, 76, 8,
                   27, 38, 32, 76, 45, 47, 40, 37, 76, 27, 76, 45,
                   34, 27, 46, 46, 31, 44, 31, 30, 76, 48, 35, 45,
                   27, 33, 31, 76, 38, 35, 31, 45, 64, 76, 49, 34,
                   41, 45, 31, 76, 32, 44, 41, 49, 40, 64, 78, 76,
                   76, 76, 76, 76, 76, 76, 76, 1, 40, 30, 76, 49,
                   44, 35, 40, 37, 38, 31, 30, 76, 38, 35, 42, 64,
                   76, 27, 40, 30, 76, 45, 40, 31, 31, 44, 76, 41,
                   32, 76, 29, 41, 38, 30, 76, 29, 41, 39, 39, 27,
                   40, 30, 64, 78, 76, 76, 76, 76, 76, 76, 76, 76,
                   20, 31, 38, 38, 76, 46, 34, 27, 46, 76, 35, 46,
                   45, 76, 45, 29, 47, 38, 42, 46, 41, 44, 76, 49,
                   31, 38, 38, 76, 46, 34, 41, 45, 31, 76, 42, 27,
                   45, 45, 35, 41, 40, 45, 76, 44, 31, 27, 30, 78,
                   76, 76, 76, 76, 76, 76, 76, 76, 23, 34, 35, 29,
                   34, 76, 51, 31, 46, 76, 45, 47, 44, 48, 35, 48,
                   31, 64, 76, 45, 46, 27, 39, 42, 31, 30, 76, 41,
                   40, 76, 46, 34, 31, 45, 31, 76, 38, 35, 32, 31,
                   38, 31, 45, 45, 76, 46, 34, 35, 40, 33, 45, 64,
                   78, 76, 76, 76, 76, 76, 76, 76, 76, 20, 34, 31,
                   76, 34, 27, 40, 30, 76, 46, 34, 27, 46, 76, 39,
                   41, 29, 37, 31, 30, 76, 46, 34, 31, 39, 64, 76,
                   27, 40, 30, 76, 46, 34, 31, 76, 34, 31, 27, 44,
                   46, 76, 46, 34, 27, 46, 76, 32, 31, 30, 66, 78,
                   76, 76, 76, 76, 76, 76, 76, 76, 1, 40, 30, 76,
                   41, 40, 76, 46, 34, 31, 76, 42, 31, 30, 31, 45,
                   46, 27, 38, 64, 76, 46, 34, 31, 45, 31, 76, 49,
                   41, 44, 30, 45, 76, 27, 42, 42, 31, 27, 44, 65,
                   78, 76, 76, 76, 76, 76, 76, 76, 76, 13, 51, 76,
                   40, 27, 39, 31, 76, 35, 45, 76, 15, 52, 51, 39,
                   27, 40, 30, 35, 27, 45, 64, 76, 11, 35, 40, 33,
                   76, 41, 32, 76, 11, 35, 40, 33, 45, 66, 78, 76,
                   76, 76, 76, 76, 76, 76, 76, 12, 41, 41, 37, 76,
                   41, 40, 76, 39, 51, 76, 23, 41, 44, 37, 45, 64,
                   76, 51, 31, 76, 13, 35, 33, 34, 46, 51, 64, 76,
                   27, 40, 30, 76, 30, 31, 45, 42, 27, 35, 44, 67,
                   78, 76, 76, 76, 76, 76, 76, 76, 76, 14, 41, 46,
                   34, 35, 40, 33, 76, 28, 31, 45, 35, 30, 31, 76,
                   44, 31, 39, 27, 35, 40, 45, 63, 76, 18, 41, 47,
                   40, 30, 76, 46, 34, 31, 76, 30, 31, 29, 27, 51,
                   78, 76, 76, 76, 76, 76, 76, 76, 76, 15, 32, 76,
                   46, 34, 27, 46, 76, 29, 41, 38, 41, 45, 45, 27,
                   38, 76, 23, 44, 31, 29, 37, 64, 76, 28, 41, 47,
                   40, 30, 38, 31, 45, 45, 76, 27, 40, 30, 76, 28,
                   27, 44, 31, 78, 76, 76, 76, 76, 76, 76, 76, 76,
                   20, 34, 31, 76, 38, 41, 40, 31, 76, 27, 40, 30,
                   76, 38, 31, 48, 31, 38, 76, 45, 27, 40, 30, 45,
                   76, 45, 46, 44, 31, 46, 29, 34, 76, 32, 27, 44,
                   76, 27, 49, 27, 51, 78, 76, 76, 76, 76, 76, 76,
                   76, 76]]   ),
               torch.tensor([[0, 0, 0, 1_069, 11]]   ),
               torch.tensor([[0, 0, 0, 1_069, 11]]   ),
           ]
           # fmt: on
           self.assertTrue(torch.allclose(tokens[0]  ,EXPECTED_OUTPUT[0]   )   )
           self.assertTrue(torch.allclose(tokens[1]  ,EXPECTED_OUTPUT[1]   )   )
           self.assertTrue(torch.allclose(tokens[2]  ,EXPECTED_OUTPUT[2]   )   )







       @require_torch
       def 				_a   (					self   )	->				Optional[Any]:
           import torch

           lowercase__									=    JukeboxTokenizer.from_pretrained("openai/jukebox-5b-lyrics"   )
           lowercase__									=    tokenizer(**self.metas   )["input_ids"]
           # fmt: off
           lowercase__									=    [
               torch.tensor([[
                   0, 0, 0, 1_069, 11, -1, -1, -1, -1, 9, 77, 39,
                   31, 46, 77, 27, 77, 46, 44, 27, 48, 31, 38, 38,
                   31, 44, 77, 32, 44, 41, 39, 77, 27, 40, 77, 27,
                   40, 46, 35, 43, 47, 31, 77, 38, 27, 40, 30, 64,
                   79, 77, 77, 77, 77, 77, 77, 77, 77, 23, 34, 41,
                   77, 45, 27, 35, 30, 77, 72, 20, 49, 41, 77, 48,
                   27, 45, 46, 77, 27, 40, 30, 77, 46, 44, 47, 40,
                   37, 38, 31, 45, 45, 77, 38, 31, 33, 45, 77, 41,
                   32, 77, 45, 46, 41, 40, 31, 79, 77, 77, 77, 77,
                   77, 77, 77, 77, 19, 46, 27, 40, 30, 77, 35, 40,
                   77, 46, 34, 31, 77, 30, 31, 45, 31, 44, 46, 63,
                   77, 63, 77, 63, 77, 63, 77, 14, 31, 27, 44, 77,
                   46, 34, 31, 39, 64, 77, 41, 40, 77, 46, 34, 31,
                   77, 45, 27, 40, 30, 64, 79, 77, 77, 77, 77, 77,
                   77, 77, 77, 8, 27, 38, 32, 77, 45, 47, 40, 37,
                   77, 27, 77, 45, 34, 27, 46, 46, 31, 44, 31, 30,
                   77, 48, 35, 45, 27, 33, 31, 77, 38, 35, 31, 45,
                   64, 77, 49, 34, 41, 45, 31, 77, 32, 44, 41, 49,
                   40, 64, 79, 77, 77, 77, 77, 77, 77, 77, 77, 1,
                   40, 30, 77, 49, 44, 35, 40, 37, 38, 31, 30, 77,
                   38, 35, 42, 64, 77, 27, 40, 30, 77, 45, 40, 31,
                   31, 44, 77, 41, 32, 77, 29, 41, 38, 30, 77, 29,
                   41, 39, 39, 27, 40, 30, 64, 79, 77, 77, 77, 77,
                   77, 77, 77, 77, 20, 31, 38, 38, 77, 46, 34, 27,
                   46, 77, 35, 46, 45, 77, 45, 29, 47, 38, 42, 46,
                   41, 44, 77, 49, 31, 38, 38, 77, 46, 34, 41, 45,
                   31, 77, 42, 27, 45, 45, 35, 41, 40, 45, 77, 44,
                   31, 27, 30, 79, 77, 77, 77, 77, 77, 77, 77, 77,
                   23, 34, 35, 29, 34, 77, 51, 31, 46, 77, 45, 47,
                   44, 48, 35, 48, 31, 64, 77, 45, 46, 27, 39, 42,
                   31, 30, 77, 41, 40, 77, 46, 34, 31, 45, 31, 77,
                   38, 35, 32, 31, 38, 31, 45, 45, 77, 46, 34, 35,
                   40, 33, 45, 64, 79, 77, 77, 77, 77, 77, 77, 77,
                   77, 20, 34, 31, 77, 34, 27, 40, 30, 77, 46, 34,
                   27, 46, 77, 39, 41, 29, 37, 31, 30, 77, 46, 34,
                   31, 39, 64, 77, 27, 40, 30, 77, 46, 34, 31, 77,
                   34, 31, 27, 44, 46, 77, 46, 34, 27, 46, 77, 32,
                   31, 30, 66, 79, 77, 77, 77, 77, 77, 77, 77, 77,
                   1, 40, 30, 77, 41, 40, 77, 46, 34, 31, 77, 42,
                   31, 30, 31, 45, 46, 27, 38, 64, 77, 46, 34, 31,
                   45, 31, 77, 49, 41, 44, 30, 45, 77, 27, 42, 42,
                   31, 27, 44, 65, 79, 77, 77, 77, 77, 77, 77, 77,
                   77, 13, 51, 77, 40, 27, 39, 31, 77, 35, 45, 77,
                   15, 52, 51, 39, 27, 40, 30, 35, 27, 45, 64, 77,
                   11, 35, 40, 33, 77, 41, 32, 77, 11, 35, 40, 33,
                   45, 66, 79, 77, 77, 77, 77, 77, 77, 77, 77, 12,
                   41, 41, 37, 77, 41, 40, 77, 39, 51, 77, 23, 41,
                   44, 37, 45, 64, 77, 51, 31, 77, 13, 35, 33, 34,
                   46, 51, 64, 77, 27, 40, 30, 77, 30, 31, 45, 42,
                   27, 35, 44, 67, 79, 77, 77, 77, 77, 77, 77, 77,
                   77, 14, 41, 46, 34, 35, 40, 33, 77, 28, 31, 45,
                   35, 30, 31, 77, 44, 31, 39, 27, 35, 40, 45, 63,
                   77, 18, 41, 47, 40, 30, 77, 46, 34, 31, 77, 30,
                   31, 29, 27, 51, 79, 77, 77, 77, 77, 77, 77, 77,
                   77, 15, 32, 77, 46, 34, 27, 46, 77, 29, 41, 38,
                   41, 45, 45, 27, 38, 77, 23, 44, 31, 29, 37, 64,
                   77, 28, 41, 47, 40, 30, 38, 31, 45, 45, 77, 27,
                   40, 30, 77, 28, 27, 44, 31, 79, 77, 77, 77, 77,
                   77, 77, 77, 77, 20, 34, 31, 77, 38, 41, 40, 31,
                   77, 27, 40, 30, 77, 38, 31, 48, 31, 38, 77, 45,
                   27, 40, 30, 45, 77, 45, 46, 44, 31, 46, 29, 34,
                   77, 32, 27, 44, 77, 27, 49, 27, 51, 79, 77, 77,
                   77, 77, 77, 77, 77, 77]]   ),
               torch.tensor([[0, 0, 0, 1_069, 11, -1, -1, -1, -1]]   ),
               torch.tensor([[0, 0, 0, 1_069, 11, -1, -1, -1, -1]]   ),
           ]
           # fmt: on
           self.assertTrue(torch.allclose(tokens[0]  ,EXPECTED_OUTPUT[0]   )   )
           self.assertTrue(torch.allclose(tokens[1]  ,EXPECTED_OUTPUT[1]   )   )
           self.assertTrue(torch.allclose(tokens[2]  ,EXPECTED_OUTPUT[2]   )   )




