Generates an up-to-date model table from the content of the auto modules.
()
| 86 | |
| 87 | |
| 88 | def get_model_table_from_auto_modules(): |
| 89 | """Generates an up-to-date model table from the content of the auto modules.""" |
| 90 | # Dictionary model names to config. |
| 91 | config_mapping_names = diffusers_module.models.auto.configuration_auto.CONFIG_MAPPING_NAMES |
| 92 | model_name_to_config = { |
| 93 | name: config_mapping_names[code] |
| 94 | for code, name in diffusers_module.MODEL_NAMES_MAPPING.items() |
| 95 | if code in config_mapping_names |
| 96 | } |
| 97 | model_name_to_prefix = {name: config.replace("ConfigMixin", "") for name, config in model_name_to_config.items()} |
| 98 | |
| 99 | # Dictionaries flagging if each model prefix has a slow/fast tokenizer, backend in PT/TF/Flax. |
| 100 | slow_tokenizers = collections.defaultdict(bool) |
| 101 | fast_tokenizers = collections.defaultdict(bool) |
| 102 | pt_models = collections.defaultdict(bool) |
| 103 | tf_models = collections.defaultdict(bool) |
| 104 | flax_models = collections.defaultdict(bool) |
| 105 | |
| 106 | # Let's lookup through all diffusers object (once). |
| 107 | for attr_name in dir(diffusers_module): |
| 108 | lookup_dict = None |
| 109 | if attr_name.endswith("Tokenizer"): |
| 110 | lookup_dict = slow_tokenizers |
| 111 | attr_name = attr_name[:-9] |
| 112 | elif attr_name.endswith("TokenizerFast"): |
| 113 | lookup_dict = fast_tokenizers |
| 114 | attr_name = attr_name[:-13] |
| 115 | elif _re_tf_models.match(attr_name) is not None: |
| 116 | lookup_dict = tf_models |
| 117 | attr_name = _re_tf_models.match(attr_name).groups()[0] |
| 118 | elif _re_flax_models.match(attr_name) is not None: |
| 119 | lookup_dict = flax_models |
| 120 | attr_name = _re_flax_models.match(attr_name).groups()[0] |
| 121 | elif _re_pt_models.match(attr_name) is not None: |
| 122 | lookup_dict = pt_models |
| 123 | attr_name = _re_pt_models.match(attr_name).groups()[0] |
| 124 | |
| 125 | if lookup_dict is not None: |
| 126 | while len(attr_name) > 0: |
| 127 | if attr_name in model_name_to_prefix.values(): |
| 128 | lookup_dict[attr_name] = True |
| 129 | break |
| 130 | # Try again after removing the last word in the name |
| 131 | attr_name = "".join(camel_case_split(attr_name)[:-1]) |
| 132 | |
| 133 | # Let's build that table! |
| 134 | model_names = list(model_name_to_config.keys()) |
| 135 | model_names.sort(key=str.lower) |
| 136 | columns = ["Model", "Tokenizer slow", "Tokenizer fast", "PyTorch support", "TensorFlow support", "Flax Support"] |
| 137 | # We'll need widths to properly display everything in the center (+2 is to leave one extra space on each side). |
| 138 | widths = [len(c) + 2 for c in columns] |
| 139 | widths[0] = max([len(name) for name in model_names]) + 2 |
| 140 | |
| 141 | # Build the table per se |
| 142 | table = "|" + "|".join([_center_text(c, w) for c, w in zip(columns, widths)]) + "|\n" |
| 143 | # Use ":-----:" format to center-aligned table cell texts |
| 144 | table += "|" + "|".join([":" + "-" * (w - 2) + ":" for w in widths]) + "|\n" |
| 145 |
no test coverage detected