(
output_path,
all,
model_types,
models_to_skip,
no_check,
upload,
organization,
token,
num_workers=1,
)
| 1681 | |
| 1682 | |
| 1683 | def create_tiny_models( |
| 1684 | output_path, |
| 1685 | all, |
| 1686 | model_types, |
| 1687 | models_to_skip, |
| 1688 | no_check, |
| 1689 | upload, |
| 1690 | organization, |
| 1691 | token, |
| 1692 | num_workers=1, |
| 1693 | ): |
| 1694 | clone_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
| 1695 | if os.getcwd() != clone_path: |
| 1696 | raise ValueError(f"This script should be run from the root of the clone of `transformers` {clone_path}") |
| 1697 | |
| 1698 | report_path = os.path.join(output_path, "reports") |
| 1699 | os.makedirs(report_path, exist_ok=True) |
| 1700 | |
| 1701 | _pytorch_arch_mappings = [x for x in dir(transformers_module) if x.startswith("MODEL_") and x.endswith("_MAPPING")] |
| 1702 | |
| 1703 | pytorch_arch_mappings = [getattr(transformers_module, x) for x in _pytorch_arch_mappings] |
| 1704 | |
| 1705 | config_classes = CONFIG_MAPPING.values() |
| 1706 | if not all: |
| 1707 | config_classes = [CONFIG_MAPPING[model_type] for model_type in model_types] |
| 1708 | |
| 1709 | # TODO: we should add information to the reports instead of skip them |
| 1710 | config_classes = [x for x in config_classes if x.__name__ not in no_model_tester_at_all] |
| 1711 | config_classes = [x for x in config_classes if x.__name__ not in configs_requiring_too_exotic_dependency] |
| 1712 | config_classes = [x for x in config_classes if x.__name__ not in deprecated_models] |
| 1713 | config_classes = [x for x in config_classes if x.__name__ not in config_without_meaningful_model_class] |
| 1714 | |
| 1715 | # A map from config classes to tuples of processors (tokenizer, feature extractor, processor) classes |
| 1716 | processor_type_map = {c: get_processor_types_from_config_class(c) for c in config_classes} |
| 1717 | |
| 1718 | to_create = {} |
| 1719 | for c in config_classes: |
| 1720 | processors = processor_type_map[c] |
| 1721 | models = get_architectures_from_config_class(c, pytorch_arch_mappings, models_to_skip) |
| 1722 | if len(models) > 0: |
| 1723 | to_create[c] = {"processor": processors, "pytorch": models} |
| 1724 | |
| 1725 | results = {} |
| 1726 | if num_workers <= 1: |
| 1727 | for c, models_to_create in list(to_create.items()): |
| 1728 | print(f"Create models for {c.__name__} ...") |
| 1729 | result = build(c, models_to_create, output_dir=os.path.join(output_path, c.model_type)) |
| 1730 | results[c.__name__] = result |
| 1731 | print("=" * 40) |
| 1732 | else: |
| 1733 | all_build_args = [] |
| 1734 | for c, models_to_create in list(to_create.items()): |
| 1735 | all_build_args.append((c, models_to_create, os.path.join(output_path, c.model_type))) |
| 1736 | with multiprocessing.Pool(processes=num_workers) as pool: |
| 1737 | results = pool.starmap(build, all_build_args) |
| 1738 | results = {build_args[0].__name__: result for build_args, result in zip(all_build_args, results)} |
| 1739 | |
| 1740 | print(results) |
no test coverage detected