usrbinenv python 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license save a randomly initialized version of a model using a pretrained config args configname which config to use savedir where to save the resulting model and tokenizer configkwargs passed to autoconfig usage saverandomlyinitializedversionfacebookbartlargecnn distilbartrandomcnn63 encoderlayers6 decoderlayers3 numbeams3 usr bin env python 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license save a randomly initialized version of a model using a pretrained config args config_name which config to use save_dir where to save the resulting model and tokenizer config_kwargs passed to autoconfig usage save_randomly_initialized_version facebook bart large cnn distilbart_random_cnn_6_3 encoder_layers 6 decoder_layers 3 num_beams 3
import fire

from transformers import AutoConfig, AutoModelForSeq2SeqLM, AutoTokenizer


def save_randomly_initialized_version(config_name: str, save_dir: str, **config_kwargs):
    
    cfg = AutoConfig.from_pretrained(config_name, **config_kwargs)
    model = AutoModelForSeq2SeqLM.from_config(cfg)
    model.save_pretrained(save_dir)
    AutoTokenizer.from_pretrained(config_name).save_pretrained(save_dir)
    return model


if __name__ == "__main__":
    fire.Fire(save_randomly_initialized_version)