├── scripts ├── init.py ├── eval_func │ ├── meteor │ │ ├── init.py │ │ ├── __init__.py │ │ ├── meteor-1.5.jar │ │ └── meteor.py │ ├── rouge │ │ ├── init.py │ │ ├── __init__.py │ │ └── rouge.py │ ├── spice │ │ └── ini.py │ ├── bleu │ │ ├── __init__.py │ │ ├── LICENSE │ │ └── bleu.py │ └── cider │ │ ├── __init__.py │ │ └── cider.py ├── improved_diffusion │ ├── init.py │ ├── transformerK │ │ ├── benchmark │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── benchmark.cpython-39.pyc │ │ │ │ ├── benchmark_args.cpython-39.pyc │ │ │ │ ├── benchmark_tf.cpython-39.pyc │ │ │ │ ├── benchmark_utils.cpython-39.pyc │ │ │ │ ├── benchmark_args_tf.cpython-39.pyc │ │ │ │ └── benchmark_args_utils.cpython-39.pyc │ │ │ └── benchmark_args.py │ │ ├── models │ │ │ ├── init.py │ │ │ └── bert │ │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── modeling_bert.cpython-38.pyc │ │ │ │ ├── modeling_bert.cpython-39.pyc │ │ │ │ ├── modeling_bert_CC.cpython-39.pyc │ │ │ │ ├── modeling_tf_bert.cpython-39.pyc │ │ │ │ ├── tokenization_bert.cpython-39.pyc │ │ │ │ ├── configuration_bert.cpython-38.pyc │ │ │ │ ├── configuration_bert.cpython-39.pyc │ │ │ │ ├── modeling_flax_bert.cpython-39.pyc │ │ │ │ ├── tokenization_bert_fast.cpython-39.pyc │ │ │ │ ├── tokenization_bert_tf.cpython-39.pyc │ │ │ │ ├── convert_bert_original_tf2_checkpoint_to_pytorch.cpython-39.pyc │ │ │ │ ├── convert_bert_original_tf_checkpoint_to_pytorch.cpython-39.pyc │ │ │ │ ├── convert_bert_pytorch_checkpoint_to_original_tf.cpython-39.pyc │ │ │ │ └── convert_bert_token_dropping_original_tf2_checkpoint_to_pytorch.cpython-39.pyc │ │ │ │ ├── convert_bert_original_tf_checkpoint_to_pytorch.py │ │ │ │ └── convert_bert_pytorch_checkpoint_to_original_tf.py │ │ ├── utils │ │ │ ├── __pycache__ │ │ │ │ ├── doc.cpython-38.pyc │ │ │ │ ├── doc.cpython-39.pyc │ │ │ │ ├── fx.cpython-39.pyc │ │ │ │ ├── hub.cpython-38.pyc │ │ │ │ ├── hub.cpython-39.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── generic.cpython-38.pyc │ │ │ │ ├── generic.cpython-39.pyc │ │ │ │ ├── logging.cpython-38.pyc │ │ │ │ ├── logging.cpython-39.pyc │ │ │ │ ├── notebook.cpython-39.pyc │ │ │ │ ├── versions.cpython-38.pyc │ │ │ │ ├── versions.cpython-39.pyc │ │ │ │ ├── constants.cpython-38.pyc │ │ │ │ ├── constants.cpython-39.pyc │ │ │ │ ├── hp_naming.cpython-39.pyc │ │ │ │ ├── peft_utils.cpython-38.pyc │ │ │ │ ├── peft_utils.cpython-39.pyc │ │ │ │ ├── bitsandbytes.cpython-39.pyc │ │ │ │ ├── import_utils.cpython-38.pyc │ │ │ │ ├── import_utils.cpython-39.pyc │ │ │ │ ├── backbone_utils.cpython-39.pyc │ │ │ │ ├── dummy_flax_objects.cpython-38.pyc │ │ │ │ ├── dummy_flax_objects.cpython-39.pyc │ │ │ │ ├── dummy_pt_objects.cpython-39.pyc │ │ │ │ ├── dummy_tf_objects.cpython-38.pyc │ │ │ │ ├── dummy_tf_objects.cpython-39.pyc │ │ │ │ ├── dummy_music_objects.cpython-39.pyc │ │ │ │ ├── dummy_speech_objects.cpython-39.pyc │ │ │ │ ├── dummy_vision_objects.cpython-39.pyc │ │ │ │ ├── model_parallel_utils.cpython-39.pyc │ │ │ │ ├── quantization_config.cpython-38.pyc │ │ │ │ ├── quantization_config.cpython-39.pyc │ │ │ │ ├── dummy_keras_nlp_objects.cpython-38.pyc │ │ │ │ ├── dummy_keras_nlp_objects.cpython-39.pyc │ │ │ │ ├── sentencepiece_model_pb2.cpython-39.pyc │ │ │ │ ├── dummy_detectron2_objects.cpython-39.pyc │ │ │ │ ├── dummy_tokenizers_objects.cpython-39.pyc │ │ │ │ ├── dummy_sentencepiece_objects.cpython-38.pyc │ │ │ │ ├── dummy_sentencepiece_objects.cpython-39.pyc │ │ │ │ ├── sentencepiece_model_pb2_new.cpython-39.pyc │ │ │ │ ├── dummy_tensorflow_text_objects.cpython-38.pyc │ │ │ │ ├── dummy_tensorflow_text_objects.cpython-39.pyc │ │ │ │ ├── dummy_sentencepiece_and_tokenizers_objects.cpython-38.pyc │ │ │ │ ├── dummy_sentencepiece_and_tokenizers_objects.cpython-39.pyc │ │ │ │ ├── dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.cpython-38.pyc │ │ │ │ └── dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.cpython-39.pyc │ │ │ ├── constants.py │ │ │ ├── dummy_keras_nlp_objects.py │ │ │ ├── dummy_sentencepiece_and_tokenizers_objects.py │ │ │ ├── dummy_tensorflow_text_objects.py │ │ │ ├── dummy_detectron2_objects.py │ │ │ ├── dummy_music_objects.py │ │ │ ├── dummy_speech_objects.py │ │ │ ├── dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.py │ │ │ ├── bitsandbytes.py │ │ │ └── model_parallel_utils.py │ │ ├── onnx │ │ │ ├── __pycache__ │ │ │ │ ├── config.cpython-38.pyc │ │ │ │ ├── config.cpython-39.pyc │ │ │ │ ├── utils.cpython-38.pyc │ │ │ │ ├── utils.cpython-39.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── __main__.cpython-39.pyc │ │ │ │ ├── convert.cpython-39.pyc │ │ │ │ └── features.cpython-39.pyc │ │ │ ├── __init__.py │ │ │ └── utils.py │ │ ├── tools │ │ │ ├── __pycache__ │ │ │ │ ├── base.cpython-39.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── agents.cpython-39.pyc │ │ │ │ ├── prompts.cpython-39.pyc │ │ │ │ ├── agent_types.cpython-39.pyc │ │ │ │ ├── translation.cpython-39.pyc │ │ │ │ ├── evaluate_agent.cpython-39.pyc │ │ │ │ ├── speech_to_text.cpython-39.pyc │ │ │ │ ├── text_to_speech.cpython-39.pyc │ │ │ │ ├── image_captioning.cpython-39.pyc │ │ │ │ ├── image_segmentation.cpython-39.pyc │ │ │ │ ├── python_interpreter.cpython-39.pyc │ │ │ │ ├── text_summarization.cpython-39.pyc │ │ │ │ ├── text_classification.cpython-39.pyc │ │ │ │ ├── text_question_answering.cpython-39.pyc │ │ │ │ ├── image_question_answering.cpython-39.pyc │ │ │ │ └── document_question_answering.cpython-39.pyc │ │ │ ├── speech_to_text.py │ │ │ ├── prompts.py │ │ │ ├── text_summarization.py │ │ │ ├── image_captioning.py │ │ │ ├── text_question_answering.py │ │ │ ├── image_question_answering.py │ │ │ ├── image_segmentation.py │ │ │ ├── text_to_speech.py │ │ │ ├── text_classification.py │ │ │ ├── __init__.py │ │ │ └── document_question_answering.py │ │ ├── commands │ │ │ ├── __pycache__ │ │ │ │ ├── env.cpython-39.pyc │ │ │ │ ├── lfs.cpython-39.pyc │ │ │ │ ├── run.cpython-39.pyc │ │ │ │ ├── train.cpython-39.pyc │ │ │ │ ├── user.cpython-39.pyc │ │ │ │ ├── convert.cpython-39.pyc │ │ │ │ ├── serving.cpython-39.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── download.cpython-39.pyc │ │ │ │ ├── pt_to_tf.cpython-39.pyc │ │ │ │ ├── add_new_model.cpython-39.pyc │ │ │ │ ├── transformers_cli.cpython-39.pyc │ │ │ │ └── add_new_model_like.cpython-39.pyc │ │ │ ├── __init__.py │ │ │ ├── transformers_cli.py │ │ │ └── download.py │ │ ├── data │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ └── data_collator.cpython-39.pyc │ │ │ ├── datasets │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── glue.cpython-39.pyc │ │ │ │ │ ├── squad.cpython-39.pyc │ │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ │ └── language_modeling.cpython-39.pyc │ │ │ │ └── __init__.py │ │ │ ├── metrics │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ │ └── squad_metrics.cpython-39.pyc │ │ │ │ └── __init__.py │ │ │ ├── processors │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── glue.cpython-39.pyc │ │ │ │ │ ├── squad.cpython-39.pyc │ │ │ │ │ ├── utils.cpython-39.pyc │ │ │ │ │ ├── xnli.cpython-39.pyc │ │ │ │ │ └── __init__.cpython-39.pyc │ │ │ │ ├── __init__.py │ │ │ │ └── xnli.py │ │ │ └── __init__.py │ │ ├── pipelines │ │ │ └── __pycache__ │ │ │ │ ├── base.cpython-39.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── fill_mask.cpython-39.pyc │ │ │ │ ├── pt_utils.cpython-39.pyc │ │ │ │ ├── audio_utils.cpython-39.pyc │ │ │ │ ├── conversational.cpython-39.pyc │ │ │ │ ├── image_to_image.cpython-39.pyc │ │ │ │ ├── image_to_text.cpython-39.pyc │ │ │ │ ├── text_to_audio.cpython-39.pyc │ │ │ │ ├── depth_estimation.cpython-39.pyc │ │ │ │ ├── mask_generation.cpython-39.pyc │ │ │ │ ├── object_detection.cpython-39.pyc │ │ │ │ ├── text_generation.cpython-39.pyc │ │ │ │ ├── feature_extraction.cpython-39.pyc │ │ │ │ ├── image_segmentation.cpython-39.pyc │ │ │ │ ├── question_answering.cpython-39.pyc │ │ │ │ ├── text_classification.cpython-39.pyc │ │ │ │ ├── audio_classification.cpython-39.pyc │ │ │ │ ├── image_classification.cpython-39.pyc │ │ │ │ ├── text2text_generation.cpython-39.pyc │ │ │ │ ├── token_classification.cpython-39.pyc │ │ │ │ ├── video_classification.cpython-39.pyc │ │ │ │ ├── table_question_answering.cpython-39.pyc │ │ │ │ ├── zero_shot_classification.cpython-39.pyc │ │ │ │ ├── visual_question_answering.cpython-39.pyc │ │ │ │ ├── zero_shot_object_detection.cpython-39.pyc │ │ │ │ ├── automatic_speech_recognition.cpython-39.pyc │ │ │ │ ├── document_question_answering.cpython-39.pyc │ │ │ │ ├── zero_shot_audio_classification.cpython-39.pyc │ │ │ │ └── zero_shot_image_classification.cpython-39.pyc │ │ ├── generation │ │ │ └── __pycache__ │ │ │ │ ├── utils.cpython-38.pyc │ │ │ │ ├── utils.cpython-39.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── tf_utils.cpython-39.pyc │ │ │ │ ├── flax_utils.cpython-39.pyc │ │ │ │ ├── streamers.cpython-39.pyc │ │ │ │ ├── beam_search.cpython-38.pyc │ │ │ │ ├── beam_search.cpython-39.pyc │ │ │ │ ├── logits_process.cpython-38.pyc │ │ │ │ ├── logits_process.cpython-39.pyc │ │ │ │ ├── beam_constraints.cpython-38.pyc │ │ │ │ ├── beam_constraints.cpython-39.pyc │ │ │ │ ├── stopping_criteria.cpython-38.pyc │ │ │ │ ├── stopping_criteria.cpython-39.pyc │ │ │ │ ├── tf_logits_process.cpython-39.pyc │ │ │ │ ├── configuration_utils.cpython-38.pyc │ │ │ │ ├── configuration_utils.cpython-39.pyc │ │ │ │ └── flax_logits_process.cpython-39.pyc │ │ ├── sagemaker │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-39.pyc │ │ │ │ ├── trainer_sm.cpython-39.pyc │ │ │ │ └── training_args_sm.cpython-39.pyc │ │ │ ├── __init__.py │ │ │ └── trainer_sm.py │ │ ├── kernels │ │ │ ├── yoso │ │ │ │ ├── common_cuda.h │ │ │ │ ├── common.h │ │ │ │ ├── fast_lsh_cumulation.h │ │ │ │ ├── common_cuda_device.h │ │ │ │ └── fast_lsh_cumulation_torch.cpp │ │ │ ├── deformable_detr │ │ │ │ ├── vision.cpp │ │ │ │ ├── cuda │ │ │ │ │ └── ms_deform_attn_cuda.h │ │ │ │ ├── cpu │ │ │ │ │ ├── ms_deform_attn_cpu.h │ │ │ │ │ └── ms_deform_attn_cpu.cpp │ │ │ │ └── ms_deform_attn.h │ │ │ ├── mra │ │ │ │ ├── cuda_launch.h │ │ │ │ ├── torch_extension.cpp │ │ │ │ └── cuda_kernel.h │ │ │ └── rwkv │ │ │ │ └── wkv_op.cpp │ │ ├── generation_tf_utils.py │ │ ├── generation_flax_utils.py │ │ ├── generation_utils.py │ │ └── file_utils.py │ ├── __init__.py │ ├── dist_util.py │ ├── fp16_util.py │ ├── img_resnet.py │ └── losses.py ├── preprocess_data.py ├── batch_nll.py ├── dataloader.py └── tree_helper.py ├── generation_outputs └── init.py ├── data └── init.py ├── datasets ├── random_t.torch └── random_emb.torch ├── testlm.sh ├── demo.sh ├── requirements.txt ├── img_preprocess.py ├── word_encode.py └── README.md /scripts/init.py: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /generation_outputs/init.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /scripts/eval_func/meteor/init.py: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /scripts/eval_func/rouge/init.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /scripts/eval_func/spice/ini.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /data/init.py: -------------------------------------------------------------------------------- 1 | #put the raw ddataset here 2 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/init.py: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /scripts/eval_func/bleu/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /scripts/eval_func/cider/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /scripts/eval_func/meteor/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /scripts/eval_func/rouge/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'vrama91' 2 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/init.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /datasets/random_t.torch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/datasets/random_t.torch -------------------------------------------------------------------------------- /datasets/random_emb.torch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/datasets/random_emb.torch -------------------------------------------------------------------------------- /scripts/improved_diffusion/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Codebase for "Improved Denoising Diffusion Probabilistic Models". 3 | """ 4 | -------------------------------------------------------------------------------- /scripts/eval_func/meteor/meteor-1.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/eval_func/meteor/meteor-1.5.jar -------------------------------------------------------------------------------- /testlm.sh: -------------------------------------------------------------------------------- 1 | CUDA_VISIBLE_DEVICES=3 python scripts/batch_decode.py diffusion_models/diff_e2e-tgt_block_rand16_transformer_lr0.0001_0.0_2000_sqrt_Lsimple_h128_s2_d0.1_sd102_xstart_e2e -1.0 ema 2 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/doc.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/doc.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/doc.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/doc.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/fx.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/fx.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/hub.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/hub.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/hub.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/hub.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/config.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/config.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/config.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/config.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/utils.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/base.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/base.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/env.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/env.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/lfs.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/lfs.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/run.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/run.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/train.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/train.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/user.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/user.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/__main__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/__main__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/convert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/convert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__pycache__/features.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/onnx/__pycache__/features.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/base.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/base.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/agents.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/agents.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/prompts.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/prompts.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/generic.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/generic.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/generic.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/generic.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/logging.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/logging.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/logging.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/logging.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/notebook.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/notebook.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/versions.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/versions.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/versions.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/versions.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/convert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/convert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/serving.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/serving.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/utils.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/constants.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/constants.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/constants.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/constants.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/hp_naming.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/hp_naming.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/peft_utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/peft_utils.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/peft_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/peft_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/download.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/download.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/pt_to_tf.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/pt_to_tf.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/__pycache__/data_collator.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/__pycache__/data_collator.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/datasets/__pycache__/glue.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/datasets/__pycache__/glue.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/datasets/__pycache__/squad.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/datasets/__pycache__/squad.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/tf_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/tf_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/fill_mask.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/fill_mask.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/pt_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/pt_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/sagemaker/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/sagemaker/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/agent_types.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/agent_types.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/translation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/translation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/bitsandbytes.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/bitsandbytes.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/import_utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/import_utils.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/import_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/import_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/metrics/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/metrics/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/__pycache__/glue.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/processors/__pycache__/glue.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/__pycache__/squad.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/processors/__pycache__/squad.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/__pycache__/utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/processors/__pycache__/utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/__pycache__/xnli.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/processors/__pycache__/xnli.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/flax_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/flax_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/streamers.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/streamers.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/audio_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/audio_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/sagemaker/__pycache__/trainer_sm.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/sagemaker/__pycache__/trainer_sm.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/evaluate_agent.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/evaluate_agent.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/speech_to_text.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/speech_to_text.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/text_to_speech.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/text_to_speech.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/backbone_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/backbone_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_args.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_args.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_tf.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_tf.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/add_new_model.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/add_new_model.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/datasets/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/datasets/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/processors/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/beam_search.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/beam_search.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/beam_search.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/beam_search.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/conversational.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/conversational.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_to_image.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_to_image.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_to_text.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_to_text.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/text_to_audio.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/text_to_audio.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/image_captioning.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/image_captioning.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/image_segmentation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/image_segmentation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/python_interpreter.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/python_interpreter.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/text_summarization.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/text_summarization.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_flax_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_flax_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_flax_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_flax_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_pt_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_pt_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tf_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tf_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tf_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tf_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/transformers_cli.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/transformers_cli.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/metrics/__pycache__/squad_metrics.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/metrics/__pycache__/squad_metrics.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/logits_process.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/logits_process.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/logits_process.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/logits_process.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_bert.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_bert.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_bert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_bert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/depth_estimation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/depth_estimation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/mask_generation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/mask_generation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/object_detection.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/object_detection.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/text_generation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/text_generation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/sagemaker/__pycache__/training_args_sm.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/sagemaker/__pycache__/training_args_sm.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/text_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/text_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_music_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_music_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_speech_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_speech_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_vision_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_vision_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/model_parallel_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/model_parallel_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/quantization_config.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/quantization_config.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/quantization_config.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/quantization_config.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_args_tf.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_args_tf.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__pycache__/add_new_model_like.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/commands/__pycache__/add_new_model_like.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/beam_constraints.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/beam_constraints.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/beam_constraints.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/beam_constraints.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/stopping_criteria.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/stopping_criteria.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/stopping_criteria.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/stopping_criteria.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/tf_logits_process.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/tf_logits_process.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_bert_CC.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_bert_CC.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_tf_bert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_tf_bert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/tokenization_bert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/tokenization_bert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/feature_extraction.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/feature_extraction.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_segmentation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_segmentation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/text_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/text_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/text_question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/text_question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_keras_nlp_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_keras_nlp_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_keras_nlp_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_keras_nlp_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/sentencepiece_model_pb2.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/sentencepiece_model_pb2.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_args_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/benchmark/__pycache__/benchmark_args_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/datasets/__pycache__/language_modeling.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/data/datasets/__pycache__/language_modeling.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/configuration_utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/configuration_utils.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/configuration_utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/configuration_utils.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation/__pycache__/flax_logits_process.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/generation/__pycache__/flax_logits_process.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/configuration_bert.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/configuration_bert.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/configuration_bert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/configuration_bert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_flax_bert.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/modeling_flax_bert.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/audio_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/audio_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/image_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/text2text_generation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/text2text_generation.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/token_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/token_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/video_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/video_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/image_question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/image_question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_detectron2_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_detectron2_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tokenizers_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tokenizers_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/tokenization_bert_fast.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/tokenization_bert_fast.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/tokenization_bert_tf.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/tokenization_bert_tf.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/table_question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/table_question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__pycache__/document_question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/tools/__pycache__/document_question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/sentencepiece_model_pb2_new.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/sentencepiece_model_pb2_new.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/visual_question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/visual_question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_object_detection.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_object_detection.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tensorflow_text_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tensorflow_text_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tensorflow_text_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_tensorflow_text_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/automatic_speech_recognition.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/automatic_speech_recognition.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/document_question_answering.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/document_question_answering.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_audio_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_audio_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_image_classification.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/pipelines/__pycache__/zero_shot_image_classification.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_and_tokenizers_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_and_tokenizers_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_and_tokenizers_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_sentencepiece_and_tokenizers_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_original_tf2_checkpoint_to_pytorch.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_original_tf2_checkpoint_to_pytorch.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_original_tf_checkpoint_to_pytorch.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_original_tf_checkpoint_to_pytorch.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_pytorch_checkpoint_to_original_tf.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_pytorch_checkpoint_to_original_tf.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_token_dropping_original_tf2_checkpoint_to_pytorch.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/models/bert/__pycache__/convert_bert_token_dropping_original_tf2_checkpoint_to_pytorch.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.cpython-38.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fay-Y/Diffusion-RSCC/HEAD/scripts/improved_diffusion/transformerK/utils/__pycache__/dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.cpython-39.pyc -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/constants.py: -------------------------------------------------------------------------------- 1 | IMAGENET_DEFAULT_MEAN = [0.485, 0.456, 0.406] 2 | IMAGENET_DEFAULT_STD = [0.229, 0.224, 0.225] 3 | IMAGENET_STANDARD_MEAN = [0.5, 0.5, 0.5] 4 | IMAGENET_STANDARD_STD = [0.5, 0.5, 0.5] 5 | OPENAI_CLIP_MEAN = [0.48145466, 0.4578275, 0.40821073] 6 | OPENAI_CLIP_STD = [0.26862954, 0.26130258, 0.27577711] 7 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/yoso/common_cuda.h: -------------------------------------------------------------------------------- 1 | 2 | #define MAX_THREADS_PER_BLOCK 1024 3 | #define OPTIMAL_THREADS_PER_BLOCK 256 4 | #define WARP_SIZE 32 5 | #define MAX_NUM_BLOCK_X 2147483647 6 | #define MAX_NUM_BLOCK_Y 65535 7 | #define MAX_NUM_BLOCK_Z 65535 8 | #define MAX_SHARED_MEM_PER_BLOCK 48000 9 | #define FULL_MASK 0xffffffff 10 | -------------------------------------------------------------------------------- /demo.sh: -------------------------------------------------------------------------------- 1 | CUDA_VISIBLE_DEVICES=2 python scripts/run_train.py --diff_steps 2000 --model_arch transformer --lr 0.0001 --lr_anneal_steps 600000 --seed 102 --noise_schedule sqrt --in_channel 16 --modality e2e-tgt --submit no --padding_mode block --app "--predict_xstart True --training_mode e2e --vocab_size 998 --e2e_train /root/Diffusion-LM/datasets/e2e_data " --notes xstart_e2e -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/yoso/common.h: -------------------------------------------------------------------------------- 1 | 2 | #define min(a, b) ((a)<(b)?(a):(b)) 3 | #define max(a, b) ((a)>(b)?(a):(b)) 4 | #define ceil_divide(a, b) ((a)/(b)+((a)%(b)!=0)) 5 | #define select(cond, a, b) ((cond)?(a):(b)) 6 | #define PI 3.141592 7 | #define EPSILON 1e-8 8 | #define MAX_VAL 1e12 9 | #define MIN_VAL -1e12 10 | #define EMPTY_VALUE -1 11 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_keras_nlp_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import DummyObject, requires_backends 3 | 4 | 5 | class TFGPT2Tokenizer(metaclass=DummyObject): 6 | _backends = ["keras_nlp"] 7 | 8 | def __init__(self, *args, **kwargs): 9 | requires_backends(self, ["keras_nlp"]) 10 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_sentencepiece_and_tokenizers_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import DummyObject, requires_backends 3 | 4 | 5 | SLOW_TO_FAST_CONVERTERS = None 6 | 7 | 8 | def convert_slow_tokenizer(*args, **kwargs): 9 | requires_backends(convert_slow_tokenizer, ["sentencepiece", "tokenizers"]) 10 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_tensorflow_text_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import DummyObject, requires_backends 3 | 4 | 5 | class TFBertTokenizer(metaclass=DummyObject): 6 | _backends = ["tensorflow_text"] 7 | 8 | def __init__(self, *args, **kwargs): 9 | requires_backends(self, ["tensorflow_text"]) 10 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_detectron2_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import requires_backends 3 | 4 | 5 | LAYOUTLM_V2_PRETRAINED_MODEL_ARCHIVE_LIST = None 6 | 7 | 8 | class LayoutLMv2Model: 9 | def __init__(self, *args, **kwargs): 10 | requires_backends(self, ["detectron2"]) 11 | 12 | @classmethod 13 | def from_pretrained(cls, *args, **kwargs): 14 | requires_backends(cls, ["detectron2"]) 15 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_music_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import DummyObject, requires_backends 3 | 4 | 5 | class Pop2PianoFeatureExtractor(metaclass=DummyObject): 6 | _backends = ["music"] 7 | 8 | def __init__(self, *args, **kwargs): 9 | requires_backends(self, ["music"]) 10 | 11 | 12 | class Pop2PianoTokenizer(metaclass=DummyObject): 13 | _backends = ["music"] 14 | 15 | def __init__(self, *args, **kwargs): 16 | requires_backends(self, ["music"]) 17 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_speech_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import DummyObject, requires_backends 3 | 4 | 5 | class ASTFeatureExtractor(metaclass=DummyObject): 6 | _backends = ["speech"] 7 | 8 | def __init__(self, *args, **kwargs): 9 | requires_backends(self, ["speech"]) 10 | 11 | 12 | class Speech2TextFeatureExtractor(metaclass=DummyObject): 13 | _backends = ["speech"] 14 | 15 | def __init__(self, *args, **kwargs): 16 | requires_backends(self, ["speech"]) 17 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/sagemaker/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .trainer_sm import SageMakerTrainer 16 | from .training_args_sm import SageMakerTrainingArguments, is_sagemaker_dp_enabled 17 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/deformable_detr/vision.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #include "ms_deform_attn.h" 12 | 13 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 14 | m.def("ms_deform_attn_forward", &ms_deform_attn_forward, "ms_deform_attn_forward"); 15 | m.def("ms_deform_attn_backward", &ms_deform_attn_backward, "ms_deform_attn_backward"); 16 | } -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/mra/cuda_launch.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define min(a, b) ((a)<(b)?(a):(b)) 6 | #define max(a, b) ((a)>(b)?(a):(b)) 7 | 8 | std::vector index_max_kernel( 9 | at::Tensor index_vals, 10 | at::Tensor indices, 11 | int A_num_block, 12 | int B_num_block 13 | ); 14 | 15 | at::Tensor mm_to_sparse_kernel( 16 | at::Tensor dense_A, 17 | at::Tensor dense_B, 18 | at::Tensor indices 19 | ); 20 | 21 | at::Tensor sparse_dense_mm_kernel( 22 | at::Tensor sparse_A, 23 | at::Tensor indices, 24 | at::Tensor dense_B, 25 | int A_num_block 26 | ); 27 | 28 | at::Tensor reduce_sum_kernel( 29 | at::Tensor sparse_A, 30 | at::Tensor indices, 31 | int A_num_block, 32 | int B_num_block 33 | ); 34 | 35 | at::Tensor scatter_kernel( 36 | at::Tensor dense_A, 37 | at::Tensor indices, 38 | int B_num_block 39 | ); 40 | -------------------------------------------------------------------------------- /scripts/preprocess_data.py: -------------------------------------------------------------------------------- 1 | import json 2 | import csv 3 | import random 4 | random.seed(10) 5 | sentence_lst = [] 6 | roc_train = 'diffusion_lm/ROCstory/ROCstory_full.csv' 7 | with open(roc_train, 'r') as csvfile: 8 | roc_reader = csv.reader(csvfile) #delimiter=' ', quotechar='|') 9 | for row in roc_reader: 10 | sentences = " ".join(row[2:]) 11 | sentence_lst.append(sentences) 12 | sentence_lst = sentence_lst[1:] 13 | print(len(sentence_lst)) 14 | print(sentence_lst[:2]) 15 | 16 | # write to dev and test sets. --> 5k valid. 17 | random.shuffle(sentence_lst) 18 | print() 19 | print(sentence_lst[:2]) 20 | valid_lst = sentence_lst[:5000] 21 | train_lst = sentence_lst[5000:] 22 | 23 | with open('diffusion_lm/ROCstory/roc_valid.json', 'w') as f: 24 | for sent in valid_lst: 25 | print(json.dumps([sent]), file=f) 26 | 27 | with open('diffusion_lm/ROCstory/roc_train.json', 'w') as f: 28 | for sent in train_lst: 29 | print(json.dumps([sent]), file=f) 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .glue import GlueDataset, GlueDataTrainingArguments 16 | from .language_modeling import ( 17 | LineByLineTextDataset, 18 | LineByLineWithRefDataset, 19 | LineByLineWithSOPTextDataset, 20 | TextDataset, 21 | TextDatasetForNextSentencePrediction, 22 | ) 23 | from .squad import SquadDataset, SquadDataTrainingArguments 24 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from abc import ABC, abstractmethod 16 | from argparse import ArgumentParser 17 | 18 | 19 | class BaseTransformersCLICommand(ABC): 20 | @staticmethod 21 | @abstractmethod 22 | def register_subcommand(parser: ArgumentParser): 23 | raise NotImplementedError() 24 | 25 | @abstractmethod 26 | def run(self): 27 | raise NotImplementedError() 28 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/dummy_essentia_and_librosa_and_pretty_midi_and_scipy_and_torch_objects.py: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by the command `make fix-copies`, do not edit. 2 | from ..utils import DummyObject, requires_backends 3 | 4 | 5 | class Pop2PianoFeatureExtractor(metaclass=DummyObject): 6 | _backends = ["essentia", "librosa", "pretty_midi", "scipy", "torch"] 7 | 8 | def __init__(self, *args, **kwargs): 9 | requires_backends(self, ["essentia", "librosa", "pretty_midi", "scipy", "torch"]) 10 | 11 | 12 | class Pop2PianoTokenizer(metaclass=DummyObject): 13 | _backends = ["essentia", "librosa", "pretty_midi", "scipy", "torch"] 14 | 15 | def __init__(self, *args, **kwargs): 16 | requires_backends(self, ["essentia", "librosa", "pretty_midi", "scipy", "torch"]) 17 | 18 | 19 | class Pop2PianoProcessor(metaclass=DummyObject): 20 | _backends = ["essentia", "librosa", "pretty_midi", "scipy", "torch"] 21 | 22 | def __init__(self, *args, **kwargs): 23 | requires_backends(self, ["essentia", "librosa", "pretty_midi", "scipy", "torch"]) 24 | -------------------------------------------------------------------------------- /scripts/batch_nll.py: -------------------------------------------------------------------------------- 1 | import os, sys, glob 2 | full_lst = glob.glob(sys.argv[1]) 3 | pattern_ = 'model' if len(sys.argv) < 2 else sys.argv[2] 4 | clamp = 'clamp' if len(sys.argv) <= 3 else sys.argv[3] 5 | print(f'pattern_ = {pattern_}', sys.argv[2]) 6 | 7 | for lst in full_lst: 8 | print(lst) 9 | try: 10 | tgt = sorted(glob.glob(f"{lst}/{pattern_}*pt"))[-1] 11 | lst = os.path.split(lst)[1] 12 | print(lst) 13 | num = 1 14 | except: 15 | continue 16 | 17 | COMMAND = f'python scripts/nll.py --clip_denoised False ' \ 18 | f'--model_path {tgt} ' \ 19 | f'--out_dir diffusion_lm/improved_diffusion/scores_eval2_valid_None ' \ 20 | f'--num_samples 64 --split valid --clamp {clamp}' 21 | print(COMMAND) 22 | os.system(COMMAND) 23 | 24 | COMMAND = f'python scripts/nll.py --clip_denoised False ' \ 25 | f'--model_path {tgt} ' \ 26 | f'--out_dir diffusion_lm/improved_diffusion/scores_eval2_valid_None ' \ 27 | f'--num_samples 64 --split train --clamp {clamp}' 28 | print(COMMAND) 29 | os.system(COMMAND) -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .glue import glue_convert_examples_to_features, glue_output_modes, glue_processors, glue_tasks_num_labels 16 | from .squad import SquadExample, SquadFeatures, SquadV1Processor, SquadV2Processor, squad_convert_examples_to_features 17 | from .utils import DataProcessor, InputExample, InputFeatures, SingleSentenceClassificationProcessor 18 | from .xnli import xnli_output_modes, xnli_processors, xnli_tasks_num_labels 19 | -------------------------------------------------------------------------------- /scripts/eval_func/bleu/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Xinlei Chen, Hao Fang, Tsung-Yi Lin, and Ramakrishna Vedantam 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/bitsandbytes.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import warnings 15 | 16 | 17 | warnings.warn( 18 | "transformers.utils.bitsandbytes module is deprecated and will be removed in a future version. Please import bitsandbytes modules directly from transformers.integrations", 19 | FutureWarning, 20 | ) 21 | 22 | from ..integrations import ( # noqa 23 | get_keys_to_not_convert, 24 | replace_8bit_linear, 25 | replace_with_bnb_linear, 26 | set_module_8bit_tensor_to_device, 27 | set_module_quantized_tensor_to_device, 28 | ) 29 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/sagemaker/trainer_sm.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import warnings 15 | 16 | from ..trainer import Trainer 17 | from ..utils import logging 18 | 19 | 20 | logger = logging.get_logger(__name__) 21 | 22 | 23 | class SageMakerTrainer(Trainer): 24 | def __init__(self, args=None, **kwargs): 25 | warnings.warn( 26 | "`SageMakerTrainer` is deprecated and will be removed in v5 of Transformers. You can use `Trainer` " 27 | "instead.", 28 | FutureWarning, 29 | ) 30 | super().__init__(args=args, **kwargs) 31 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation_tf_utils.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. 3 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import warnings 18 | 19 | from .generation import TFGenerationMixin 20 | 21 | 22 | class TFGenerationMixin(TFGenerationMixin): 23 | # warning at import time 24 | warnings.warn( 25 | "Importing `TFGenerationMixin` from `src/transformers/generation_tf_utils.py` is deprecated and will " 26 | "be removed in Transformers v5. Import as `from transformers import TFGenerationMixin` instead.", 27 | FutureWarning, 28 | ) 29 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation_flax_utils.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2021 The Google AI Flax Team Authors, and The HuggingFace Inc. team. 3 | # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import warnings 18 | 19 | from .generation import FlaxGenerationMixin 20 | 21 | 22 | class FlaxGenerationMixin(FlaxGenerationMixin): 23 | # warning at import time 24 | warnings.warn( 25 | "Importing `FlaxGenerationMixin` from `src/transformers/generation_flax_utils.py` is deprecated and will " 26 | "be removed in Transformers v5. Import as `from transformers import FlaxGenerationMixin` instead.", 27 | FutureWarning, 28 | ) 29 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/generation_utils.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2020 The Google AI Language Team Authors, Facebook AI Research authors and The HuggingFace Inc. team. 3 | # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import warnings 18 | 19 | from .generation import GenerationMixin 20 | 21 | 22 | class GenerationMixin(GenerationMixin): 23 | # warning at import time 24 | warnings.warn( 25 | "Importing `GenerationMixin` from `src/transformers/generation_utils.py` is deprecated and will " 26 | "be removed in Transformers v5. Import as `from transformers import GenerationMixin` instead.", 27 | FutureWarning, 28 | ) 29 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/deformable_detr/cuda/ms_deform_attn_cuda.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #pragma once 12 | #include 13 | 14 | at::Tensor ms_deform_attn_cuda_forward( 15 | const at::Tensor &value, 16 | const at::Tensor &spatial_shapes, 17 | const at::Tensor &level_start_index, 18 | const at::Tensor &sampling_loc, 19 | const at::Tensor &attn_weight, 20 | const int im2col_step); 21 | 22 | std::vector ms_deform_attn_cuda_backward( 23 | const at::Tensor &value, 24 | const at::Tensor &spatial_shapes, 25 | const at::Tensor &level_start_index, 26 | const at::Tensor &sampling_loc, 27 | const at::Tensor &attn_weight, 28 | const at::Tensor &grad_output, 29 | const int im2col_step); 30 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/deformable_detr/cpu/ms_deform_attn_cpu.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #pragma once 12 | #include 13 | 14 | at::Tensor 15 | ms_deform_attn_cpu_forward( 16 | const at::Tensor &value, 17 | const at::Tensor &spatial_shapes, 18 | const at::Tensor &level_start_index, 19 | const at::Tensor &sampling_loc, 20 | const at::Tensor &attn_weight, 21 | const int im2col_step); 22 | 23 | std::vector 24 | ms_deform_attn_cpu_backward( 25 | const at::Tensor &value, 26 | const at::Tensor &spatial_shapes, 27 | const at::Tensor &level_start_index, 28 | const at::Tensor &sampling_loc, 29 | const at::Tensor &attn_weight, 30 | const at::Tensor &grad_output, 31 | const int im2col_step); 32 | 33 | -------------------------------------------------------------------------------- /scripts/eval_func/bleu/bleu.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # File Name : bleu.py 4 | # 5 | # Description : Wrapper for BLEU scorer. 6 | # 7 | # Creation Date : 06-01-2015 8 | # Last Modified : Thu 19 Mar 2015 09:13:28 PM PDT 9 | # Authors : Hao Fang and Tsung-Yi Lin 10 | 11 | from .bleu_scorer import BleuScorer 12 | 13 | 14 | class Bleu: 15 | def __init__(self, n=4): 16 | # default compute Blue score up to 4 17 | self._n = n 18 | self._hypo_for_image = {} 19 | self.ref_for_image = {} 20 | 21 | def compute_score(self, gts, res): 22 | 23 | bleu_scorer = BleuScorer(n=self._n) 24 | for i in range(len(res)): 25 | hypo = res[i] 26 | ref = gts[i] 27 | 28 | # Sanity check. 29 | assert(type(hypo) is list) 30 | assert(len(hypo) == 1) 31 | assert(type(ref) is list) 32 | assert(len(ref) >= 1) 33 | 34 | bleu_scorer += (hypo[0], ref) 35 | 36 | #score, scores = bleu_scorer.compute_score(option='shortest') 37 | score, scores = bleu_scorer.compute_score(option='closest', verbose=1) 38 | #score, scores = bleu_scorer.compute_score(option='average', verbose=1) 39 | 40 | # return (bleu, bleu_info) 41 | return score, scores 42 | 43 | def method(self): 44 | return "Bleu" 45 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/deformable_detr/cpu/ms_deform_attn_cpu.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | 17 | at::Tensor 18 | ms_deform_attn_cpu_forward( 19 | const at::Tensor &value, 20 | const at::Tensor &spatial_shapes, 21 | const at::Tensor &level_start_index, 22 | const at::Tensor &sampling_loc, 23 | const at::Tensor &attn_weight, 24 | const int im2col_step) 25 | { 26 | AT_ERROR("Not implement on cpu"); 27 | } 28 | 29 | std::vector 30 | ms_deform_attn_cpu_backward( 31 | const at::Tensor &value, 32 | const at::Tensor &spatial_shapes, 33 | const at::Tensor &level_start_index, 34 | const at::Tensor &sampling_loc, 35 | const at::Tensor &attn_weight, 36 | const at::Tensor &grad_output, 37 | const int im2col_step) 38 | { 39 | AT_ERROR("Not implement on cpu"); 40 | } 41 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .data_collator import ( 16 | DataCollatorForLanguageModeling, 17 | DataCollatorForPermutationLanguageModeling, 18 | DataCollatorForSeq2Seq, 19 | DataCollatorForSOP, 20 | DataCollatorForTokenClassification, 21 | DataCollatorForWholeWordMask, 22 | DataCollatorWithPadding, 23 | DefaultDataCollator, 24 | default_data_collator, 25 | ) 26 | from .metrics import glue_compute_metrics, xnli_compute_metrics 27 | from .processors import ( 28 | DataProcessor, 29 | InputExample, 30 | InputFeatures, 31 | SingleSentenceClassificationProcessor, 32 | SquadExample, 33 | SquadFeatures, 34 | SquadV1Processor, 35 | SquadV2Processor, 36 | glue_convert_examples_to_features, 37 | glue_output_modes, 38 | glue_processors, 39 | glue_tasks_num_labels, 40 | squad_convert_examples_to_features, 41 | xnli_output_modes, 42 | xnli_processors, 43 | xnli_tasks_num_labels, 44 | ) 45 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/speech_to_text.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor 18 | from .base import PipelineTool 19 | 20 | 21 | class SpeechToTextTool(PipelineTool): 22 | default_checkpoint = "openai/whisper-base" 23 | description = ( 24 | "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the " 25 | "transcribed text." 26 | ) 27 | name = "transcriber" 28 | pre_processor_class = WhisperProcessor 29 | model_class = WhisperForConditionalGeneration 30 | 31 | inputs = ["audio"] 32 | outputs = ["text"] 33 | 34 | def encode(self, audio): 35 | return self.pre_processor(audio, return_tensors="pt").input_features 36 | 37 | def forward(self, inputs): 38 | return self.model.generate(inputs=inputs) 39 | 40 | def decode(self, outputs): 41 | return self.pre_processor.batch_decode(outputs, skip_special_tokens=True)[0] 42 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import TYPE_CHECKING 16 | 17 | from ..utils import _LazyModule 18 | 19 | 20 | _import_structure = { 21 | "config": [ 22 | "EXTERNAL_DATA_FORMAT_SIZE_LIMIT", 23 | "OnnxConfig", 24 | "OnnxConfigWithPast", 25 | "OnnxSeq2SeqConfigWithPast", 26 | "PatchingSpec", 27 | ], 28 | "convert": ["export", "validate_model_outputs"], 29 | "features": ["FeaturesManager"], 30 | "utils": ["ParameterFormat", "compute_serialized_parameters_size"], 31 | } 32 | 33 | 34 | if TYPE_CHECKING: 35 | from .config import ( 36 | EXTERNAL_DATA_FORMAT_SIZE_LIMIT, 37 | OnnxConfig, 38 | OnnxConfigWithPast, 39 | OnnxSeq2SeqConfigWithPast, 40 | PatchingSpec, 41 | ) 42 | from .convert import export, validate_model_outputs 43 | from .features import FeaturesManager 44 | from .utils import ParameterFormat, compute_serialized_parameters_size 45 | 46 | else: 47 | import sys 48 | 49 | sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__) 50 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/prompts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | import re 18 | 19 | from ..utils import cached_file 20 | 21 | 22 | # docstyle-ignore 23 | CHAT_MESSAGE_PROMPT = """ 24 | Human: <> 25 | 26 | Assistant: """ 27 | 28 | 29 | DEFAULT_PROMPTS_REPO = "huggingface-tools/default-prompts" 30 | PROMPT_FILES = {"chat": "chat_prompt_template.txt", "run": "run_prompt_template.txt"} 31 | 32 | 33 | def download_prompt(prompt_or_repo_id, agent_name, mode="run"): 34 | """ 35 | Downloads and caches the prompt from a repo and returns it contents (if necessary) 36 | """ 37 | if prompt_or_repo_id is None: 38 | prompt_or_repo_id = DEFAULT_PROMPTS_REPO 39 | 40 | # prompt is considered a repo ID when it does not contain any kind of space 41 | if re.search("\\s", prompt_or_repo_id) is not None: 42 | return prompt_or_repo_id 43 | 44 | prompt_file = cached_file( 45 | prompt_or_repo_id, PROMPT_FILES[mode], repo_type="dataset", user_agent={"agent": agent_name} 46 | ) 47 | with open(prompt_file, "r", encoding="utf-8") as f: 48 | return f.read() 49 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/mra/torch_extension.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "cuda_launch.h" 4 | #include 5 | 6 | std::vector index_max( 7 | at::Tensor index_vals, 8 | at::Tensor indices, 9 | int A_num_block, 10 | int B_num_block 11 | ) { 12 | return index_max_kernel( 13 | index_vals, 14 | indices, 15 | A_num_block, 16 | B_num_block 17 | ); 18 | } 19 | 20 | at::Tensor mm_to_sparse( 21 | at::Tensor dense_A, 22 | at::Tensor dense_B, 23 | at::Tensor indices 24 | ) { 25 | return mm_to_sparse_kernel( 26 | dense_A, 27 | dense_B, 28 | indices 29 | ); 30 | } 31 | 32 | at::Tensor sparse_dense_mm( 33 | at::Tensor sparse_A, 34 | at::Tensor indices, 35 | at::Tensor dense_B, 36 | int A_num_block 37 | ) { 38 | return sparse_dense_mm_kernel( 39 | sparse_A, 40 | indices, 41 | dense_B, 42 | A_num_block 43 | ); 44 | } 45 | 46 | at::Tensor reduce_sum( 47 | at::Tensor sparse_A, 48 | at::Tensor indices, 49 | int A_num_block, 50 | int B_num_block 51 | ) { 52 | return reduce_sum_kernel( 53 | sparse_A, 54 | indices, 55 | A_num_block, 56 | B_num_block 57 | ); 58 | } 59 | 60 | at::Tensor scatter( 61 | at::Tensor dense_A, 62 | at::Tensor indices, 63 | int B_num_block 64 | ) { 65 | return scatter_kernel( 66 | dense_A, 67 | indices, 68 | B_num_block 69 | ); 70 | } 71 | 72 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 73 | m.def("index_max", &index_max, "index_max (CUDA)"); 74 | m.def("mm_to_sparse", &mm_to_sparse, "mm_to_sparse (CUDA)"); 75 | m.def("sparse_dense_mm", &sparse_dense_mm, "sparse_dense_mm (CUDA)"); 76 | m.def("reduce_sum", &reduce_sum, "reduce_sum (CUDA)"); 77 | m.def("scatter", &scatter, "scatter (CUDA)"); 78 | } 79 | -------------------------------------------------------------------------------- /scripts/eval_func/cider/cider.py: -------------------------------------------------------------------------------- 1 | # Filename: cider.py 2 | # 3 | # Description: Describes the class to compute the CIDEr (Consensus-Based Image Description Evaluation) Metric 4 | # by Vedantam, Zitnick, and Parikh (http://arxiv.org/abs/1411.5726) 5 | # 6 | # Creation Date: Sun Feb 8 14:16:54 2015 7 | # 8 | # Authors: Ramakrishna Vedantam and Tsung-Yi Lin 9 | 10 | from eval_func.cider.cider_scorer import CiderScorer 11 | import pdb 12 | 13 | class Cider: 14 | """ 15 | Main Class to compute the CIDEr metric 16 | 17 | """ 18 | def __init__(self, test=None, refs=None, n=4, sigma=6.0): 19 | # set cider to sum over 1 to 4-grams 20 | self._n = n 21 | # set the standard deviation parameter for gaussian penalty 22 | self._sigma = sigma 23 | 24 | def compute_score(self, gts, res): 25 | """ 26 | Main function to compute CIDEr score 27 | :param hypo_for_image (dict) : dictionary with key and value 28 | ref_for_image (dict) : dictionary with key and value 29 | :return: cider (float) : computed CIDEr score for the corpus 30 | """ 31 | 32 | cider_scorer = CiderScorer(n=self._n, sigma=self._sigma) 33 | 34 | for i in range(len(res)): 35 | hypo = res[i] 36 | ref = gts[i] 37 | 38 | # Sanity check. 39 | assert(type(hypo) is list) 40 | assert(len(hypo) == 1) 41 | assert(type(ref) is list) 42 | assert(len(ref) > 0) 43 | 44 | cider_scorer += (hypo[0], ref) 45 | 46 | (score, scores) = cider_scorer.compute_score() 47 | 48 | return score, scores 49 | 50 | def method(self): 51 | return "CIDEr" -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/yoso/fast_lsh_cumulation.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | std::vector fast_hash_ver1_kernel( 6 | at::Tensor query_mask, 7 | at::Tensor query_vector, 8 | at::Tensor key_mask, 9 | at::Tensor key_vector, 10 | int num_hash_f, 11 | int hash_code_len, 12 | bool use_cuda 13 | ); 14 | 15 | at::Tensor lsh_cumulation_ver1_kernel( 16 | at::Tensor query_mask, 17 | at::Tensor query_hash_code, 18 | at::Tensor key_mask, 19 | at::Tensor key_hash_code, 20 | at::Tensor value, 21 | int hashtable_capacity, 22 | bool use_cuda 23 | ); 24 | 25 | at::Tensor lsh_weighted_cumulation_ver1_kernel( 26 | at::Tensor query_mask, 27 | at::Tensor query_hash_code, 28 | at::Tensor query_weight, 29 | at::Tensor key_mask, 30 | at::Tensor key_hash_code, 31 | at::Tensor key_weight, 32 | at::Tensor value, 33 | int hashtable_capacity, 34 | bool use_cuda 35 | ); 36 | 37 | at::Tensor lsh_weighted_cumulation_ver2_kernel( 38 | at::Tensor query_mask, 39 | at::Tensor query_hash_code, 40 | at::Tensor query_weight, 41 | at::Tensor key_mask, 42 | at::Tensor key_hash_code, 43 | at::Tensor key_weight, 44 | at::Tensor value, 45 | int hashtable_capacity, 46 | bool use_cuda 47 | ); 48 | 49 | at::Tensor lsh_weighted_cumulation_ver3_kernel( 50 | at::Tensor query_mask, 51 | at::Tensor query_hash_code, 52 | at::Tensor query_weight, 53 | at::Tensor key_mask, 54 | at::Tensor key_hash_code, 55 | at::Tensor key_weight, 56 | at::Tensor value, 57 | int hashtable_capacity, 58 | bool use_cuda 59 | ); 60 | 61 | at::Tensor lsh_weighted_cumulation_ver4_kernel( 62 | at::Tensor query_mask, 63 | at::Tensor query_hash_code, 64 | at::Tensor query_weight, 65 | at::Tensor key_mask, 66 | at::Tensor key_hash_code, 67 | at::Tensor key_weight, 68 | at::Tensor value, 69 | int hashtable_capacity, 70 | bool use_cuda 71 | ); 72 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/text_summarization.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | from ..models.auto import AutoModelForSeq2SeqLM, AutoTokenizer 18 | from .base import PipelineTool 19 | 20 | 21 | class TextSummarizationTool(PipelineTool): 22 | """ 23 | Example: 24 | 25 | ```py 26 | from transformers.tools import TextSummarizationTool 27 | 28 | summarizer = TextSummarizationTool() 29 | summarizer(long_text) 30 | ``` 31 | """ 32 | 33 | default_checkpoint = "philschmid/bart-large-cnn-samsum" 34 | description = ( 35 | "This is a tool that summarizes an English text. It takes an input `text` containing the text to summarize, " 36 | "and returns a summary of the text." 37 | ) 38 | name = "summarizer" 39 | pre_processor_class = AutoTokenizer 40 | model_class = AutoModelForSeq2SeqLM 41 | 42 | inputs = ["text"] 43 | outputs = ["text"] 44 | 45 | def encode(self, text): 46 | return self.pre_processor(text, return_tensors="pt", truncation=True) 47 | 48 | def forward(self, inputs): 49 | return self.model.generate(**inputs)[0] 50 | 51 | def decode(self, outputs): 52 | return self.pre_processor.decode(outputs, skip_special_tokens=True, clean_up_tokenization_spaces=True) 53 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/mra/cuda_kernel.h: -------------------------------------------------------------------------------- 1 | 2 | #define WARP_SIZE 32 3 | #define FULL_MASK 0xffffffff 4 | #define OPTIMAL_THREADS 256 5 | 6 | __global__ void index_max_cuda_kernel( 7 | float *index_vals, // [batch_size, 32, num_block] 8 | int *indices, // [batch_size, num_block] 9 | float *max_vals, // [batch_size, A_num_block * 32] 10 | float *max_vals_scatter, // [batch_size, 32, num_block] 11 | long batch_size, 12 | long A_num_block, 13 | long B_num_block, 14 | long num_block 15 | ); 16 | 17 | __global__ void mm_to_sparse_cuda_kernel( 18 | float *dense_A, // [batch_size, A_num_block, dim, 32] 19 | float *dense_B, // [batch_size, B_num_block, dim, 32] 20 | int *indices, // [batch_size, num_block] 21 | float *sparse_C, // [batch_size, num_block, 32, 32] 22 | long batch_size, 23 | long A_num_block, 24 | long B_num_block, 25 | long dim, 26 | long num_block 27 | ); 28 | 29 | __global__ void sparse_dense_mm_cuda_kernel( 30 | float *sparse_A, // [batch_size, num_block, 32, 32] 31 | int *indices, // [batch_size, num_block] 32 | float *dense_B, // [batch_size, B_num_block, dim, 32] 33 | float *dense_C, // [batch_size, A_num_block, dim, 32] 34 | long batch_size, 35 | long A_num_block, 36 | long B_num_block, 37 | long dim, 38 | long num_block 39 | ); 40 | 41 | __global__ void reduce_sum_cuda_kernel( 42 | float *sparse_A, // [batch_size, num_block, 32, 32] 43 | int *indices, // [batch_size, num_block] 44 | float *dense_C, // [batch_size, A_num_block, 32] 45 | long batch_size, 46 | long A_num_block, 47 | long B_num_block, 48 | long num_block 49 | ); 50 | 51 | __global__ void scatter_cuda_kernel( 52 | float *dense_A, // [batch_size, A_num_block, 32] 53 | int *indices, // [batch_size, num_block] 54 | float *sparse_C, // [batch_size, num_block, 32, 32] 55 | long batch_size, 56 | long A_num_block, 57 | long B_num_block, 58 | long num_block 59 | ); 60 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/image_captioning.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | from typing import TYPE_CHECKING 18 | 19 | from ..models.auto import AutoModelForVision2Seq 20 | from ..utils import requires_backends 21 | from .base import PipelineTool 22 | 23 | 24 | if TYPE_CHECKING: 25 | from PIL import Image 26 | 27 | 28 | class ImageCaptioningTool(PipelineTool): 29 | default_checkpoint = "Salesforce/blip-image-captioning-base" 30 | description = ( 31 | "This is a tool that generates a description of an image. It takes an input named `image` which should be the " 32 | "image to caption, and returns a text that contains the description in English." 33 | ) 34 | name = "image_captioner" 35 | model_class = AutoModelForVision2Seq 36 | 37 | inputs = ["image"] 38 | outputs = ["text"] 39 | 40 | def __init__(self, *args, **kwargs): 41 | requires_backends(self, ["vision"]) 42 | super().__init__(*args, **kwargs) 43 | 44 | def encode(self, image: "Image"): 45 | return self.pre_processor(images=image, return_tensors="pt") 46 | 47 | def forward(self, inputs): 48 | return self.model.generate(**inputs) 49 | 50 | def decode(self, outputs): 51 | return self.pre_processor.batch_decode(outputs, skip_special_tokens=True)[0].strip() 52 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/deformable_detr/ms_deform_attn.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "cpu/ms_deform_attn_cpu.h" 14 | 15 | #ifdef WITH_CUDA 16 | #include "cuda/ms_deform_attn_cuda.h" 17 | #endif 18 | 19 | 20 | at::Tensor 21 | ms_deform_attn_forward( 22 | const at::Tensor &value, 23 | const at::Tensor &spatial_shapes, 24 | const at::Tensor &level_start_index, 25 | const at::Tensor &sampling_loc, 26 | const at::Tensor &attn_weight, 27 | const int im2col_step) 28 | { 29 | if (value.type().is_cuda()) 30 | { 31 | #ifdef WITH_CUDA 32 | return ms_deform_attn_cuda_forward( 33 | value, spatial_shapes, level_start_index, sampling_loc, attn_weight, im2col_step); 34 | #else 35 | AT_ERROR("Not compiled with GPU support"); 36 | #endif 37 | } 38 | AT_ERROR("Not implemented on the CPU"); 39 | } 40 | 41 | std::vector 42 | ms_deform_attn_backward( 43 | const at::Tensor &value, 44 | const at::Tensor &spatial_shapes, 45 | const at::Tensor &level_start_index, 46 | const at::Tensor &sampling_loc, 47 | const at::Tensor &attn_weight, 48 | const at::Tensor &grad_output, 49 | const int im2col_step) 50 | { 51 | if (value.type().is_cuda()) 52 | { 53 | #ifdef WITH_CUDA 54 | return ms_deform_attn_cuda_backward( 55 | value, spatial_shapes, level_start_index, sampling_loc, attn_weight, grad_output, im2col_step); 56 | #else 57 | AT_ERROR("Not compiled with GPU support"); 58 | #endif 59 | } 60 | AT_ERROR("Not implemented on the CPU"); 61 | } 62 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/text_question_answering.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | from ..models.auto import AutoModelForSeq2SeqLM, AutoTokenizer 18 | from .base import PipelineTool 19 | 20 | 21 | QA_PROMPT = """Here is a text containing a lot of information: '''{text}'''. 22 | 23 | Can you answer this question about the text: '{question}'""" 24 | 25 | 26 | class TextQuestionAnsweringTool(PipelineTool): 27 | default_checkpoint = "google/flan-t5-base" 28 | description = ( 29 | "This is a tool that answers questions related to a text. It takes two arguments named `text`, which is the " 30 | "text where to find the answer, and `question`, which is the question, and returns the answer to the question." 31 | ) 32 | name = "text_qa" 33 | pre_processor_class = AutoTokenizer 34 | model_class = AutoModelForSeq2SeqLM 35 | 36 | inputs = ["text", "text"] 37 | outputs = ["text"] 38 | 39 | def encode(self, text: str, question: str): 40 | prompt = QA_PROMPT.format(text=text, question=question) 41 | return self.pre_processor(prompt, return_tensors="pt") 42 | 43 | def forward(self, inputs): 44 | output_ids = self.model.generate(**inputs) 45 | 46 | in_b, _ = inputs["input_ids"].shape 47 | out_b = output_ids.shape[0] 48 | 49 | return output_ids.reshape(in_b, out_b // in_b, *output_ids.shape[1:])[0][0] 50 | 51 | def decode(self, outputs): 52 | return self.pre_processor.decode(outputs, skip_special_tokens=True, clean_up_tokenization_spaces=True) 53 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/image_question_answering.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | from typing import TYPE_CHECKING 18 | 19 | import torch 20 | 21 | from ..models.auto import AutoModelForVisualQuestionAnswering, AutoProcessor 22 | from ..utils import requires_backends 23 | from .base import PipelineTool 24 | 25 | 26 | if TYPE_CHECKING: 27 | from PIL import Image 28 | 29 | 30 | class ImageQuestionAnsweringTool(PipelineTool): 31 | default_checkpoint = "dandelin/vilt-b32-finetuned-vqa" 32 | description = ( 33 | "This is a tool that answers a question about an image. It takes an input named `image` which should be the " 34 | "image containing the information, as well as a `question` which should be the question in English. It " 35 | "returns a text that is the answer to the question." 36 | ) 37 | name = "image_qa" 38 | pre_processor_class = AutoProcessor 39 | model_class = AutoModelForVisualQuestionAnswering 40 | 41 | inputs = ["image", "text"] 42 | outputs = ["text"] 43 | 44 | def __init__(self, *args, **kwargs): 45 | requires_backends(self, ["vision"]) 46 | super().__init__(*args, **kwargs) 47 | 48 | def encode(self, image: "Image", question: str): 49 | return self.pre_processor(image, question, return_tensors="pt") 50 | 51 | def forward(self, inputs): 52 | with torch.no_grad(): 53 | return self.model(**inputs).logits 54 | 55 | def decode(self, outputs): 56 | idx = outputs.argmax(-1).item() 57 | return self.model.config.id2label[idx] 58 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/dist_util.py: -------------------------------------------------------------------------------- 1 | """ 2 | Helpers for distributed training. 3 | """ 4 | 5 | import io 6 | import os 7 | import socket 8 | 9 | import blobfile as bf 10 | from mpi4py import MPI 11 | import torch as th 12 | import torch.distributed as dist 13 | 14 | # Change this to reflect your cluster layout. 15 | # The GPU for a given rank is (rank % GPUS_PER_NODE). 16 | GPUS_PER_NODE = 1 #8 17 | 18 | SETUP_RETRY_COUNT = 3 19 | 20 | 21 | def setup_dist(): 22 | """ 23 | Setup a distributed process group. 24 | """ 25 | if dist.is_initialized(): 26 | return 27 | 28 | comm = MPI.COMM_WORLD 29 | backend = "gloo" if not th.cuda.is_available() else "nccl" 30 | 31 | if backend == "gloo": 32 | hostname = "localhost" 33 | else: 34 | hostname = socket.gethostbyname(socket.getfqdn()) 35 | os.environ["MASTER_ADDR"] = comm.bcast(hostname, root=0) 36 | os.environ["RANK"] = str(comm.rank) 37 | os.environ["WORLD_SIZE"] = str(comm.size) 38 | 39 | port = comm.bcast(_find_free_port(), root=0) 40 | os.environ["MASTER_PORT"] = str(port) 41 | dist.init_process_group(backend=backend, init_method="env://") 42 | 43 | 44 | def dev(): 45 | """ 46 | Get the device to use for torch.distributed. 47 | """ 48 | if th.cuda.is_available(): 49 | return th.device(f"cuda:{MPI.COMM_WORLD.Get_rank() % GPUS_PER_NODE}") 50 | return th.device("cpu") 51 | 52 | 53 | def load_state_dict(path, **kwargs): 54 | """ 55 | Load a PyTorch file without redundant fetches across MPI ranks. 56 | """ 57 | if MPI.COMM_WORLD.Get_rank() == 0: 58 | with bf.BlobFile(path, "rb") as f: 59 | data = f.read() 60 | else: 61 | data = None 62 | data = MPI.COMM_WORLD.bcast(data) 63 | return th.load(io.BytesIO(data), **kwargs) 64 | 65 | 66 | def sync_params(params): 67 | """ 68 | Synchronize a sequence of Tensors across ranks from rank 0. 69 | """ 70 | for p in params: 71 | with th.no_grad(): 72 | dist.broadcast(p, 0) 73 | 74 | 75 | def _find_free_port(): 76 | try: 77 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 78 | s.bind(("", 0)) 79 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 80 | return s.getsockname()[1] 81 | finally: 82 | s.close() 83 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/transformers_cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright 2020 The HuggingFace Team. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | from argparse import ArgumentParser 17 | 18 | from .add_new_model import AddNewModelCommand 19 | from .add_new_model_like import AddNewModelLikeCommand 20 | from .convert import ConvertCommand 21 | from .download import DownloadCommand 22 | from .env import EnvironmentCommand 23 | from .lfs import LfsCommands 24 | from .pt_to_tf import PTtoTFCommand 25 | from .run import RunCommand 26 | from .serving import ServeCommand 27 | from .user import UserCommands 28 | 29 | 30 | def main(): 31 | parser = ArgumentParser("Transformers CLI tool", usage="transformers-cli []") 32 | commands_parser = parser.add_subparsers(help="transformers-cli command helpers") 33 | 34 | # Register commands 35 | ConvertCommand.register_subcommand(commands_parser) 36 | DownloadCommand.register_subcommand(commands_parser) 37 | EnvironmentCommand.register_subcommand(commands_parser) 38 | RunCommand.register_subcommand(commands_parser) 39 | ServeCommand.register_subcommand(commands_parser) 40 | UserCommands.register_subcommand(commands_parser) 41 | AddNewModelCommand.register_subcommand(commands_parser) 42 | AddNewModelLikeCommand.register_subcommand(commands_parser) 43 | LfsCommands.register_subcommand(commands_parser) 44 | PTtoTFCommand.register_subcommand(commands_parser) 45 | 46 | # Let's go 47 | args = parser.parse_args() 48 | 49 | if not hasattr(args, "func"): 50 | parser.print_help() 51 | exit(1) 52 | 53 | # Run 54 | service = args.func(args) 55 | service.run() 56 | 57 | 58 | if __name__ == "__main__": 59 | main() 60 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/image_segmentation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | import numpy as np 18 | import torch 19 | 20 | from ..models.clipseg import CLIPSegForImageSegmentation 21 | from ..utils import is_vision_available, requires_backends 22 | from .base import PipelineTool 23 | 24 | 25 | if is_vision_available(): 26 | from PIL import Image 27 | 28 | 29 | class ImageSegmentationTool(PipelineTool): 30 | description = ( 31 | "This is a tool that creates a segmentation mask of an image according to a label. It cannot create an image. " 32 | "It takes two arguments named `image` which should be the original image, and `label` which should be a text " 33 | "describing the elements what should be identified in the segmentation mask. The tool returns the mask." 34 | ) 35 | default_checkpoint = "CIDAS/clipseg-rd64-refined" 36 | name = "image_segmenter" 37 | model_class = CLIPSegForImageSegmentation 38 | 39 | inputs = ["image", "text"] 40 | outputs = ["image"] 41 | 42 | def __init__(self, *args, **kwargs): 43 | requires_backends(self, ["vision"]) 44 | super().__init__(*args, **kwargs) 45 | 46 | def encode(self, image: "Image", label: str): 47 | return self.pre_processor(text=[label], images=[image], padding=True, return_tensors="pt") 48 | 49 | def forward(self, inputs): 50 | with torch.no_grad(): 51 | logits = self.model(**inputs).logits 52 | return logits 53 | 54 | def decode(self, outputs): 55 | array = outputs.cpu().detach().numpy() 56 | array[array <= 0] = 0 57 | array[array > 0] = 1 58 | return Image.fromarray((array * 255).astype(np.uint8)) 59 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/yoso/common_cuda_device.h: -------------------------------------------------------------------------------- 1 | 2 | #include "common.h" 3 | 4 | template 5 | __device__ int set_insert(T *set, int set_size, T value) { 6 | int slot = value % set_size; 7 | int start_slot = slot; 8 | while (true) { 9 | T prev = atomicCAS(&set[slot], EMPTY_VALUE, value); 10 | if (prev == EMPTY_VALUE || prev == value) { 11 | return slot; 12 | } 13 | slot = (slot + 1) % set_size; 14 | if (slot == start_slot) { 15 | return -1; 16 | } 17 | } 18 | return -1; 19 | } 20 | 21 | template 22 | __device__ int set_lookup(T *set, int set_size, T value) { 23 | int slot = value % set_size; 24 | int start_slot = slot; 25 | while (true) { 26 | if (set[slot] == value) { 27 | return slot; 28 | } 29 | slot = (slot + 1) % set_size; 30 | if (slot == start_slot) { 31 | return -1; 32 | } 33 | } 34 | return -1; 35 | } 36 | 37 | template 38 | __device__ void init_buffer(T init_value, T *buffer, int buffer_size, int num_threads, int thread_id) { 39 | __syncthreads(); 40 | for (int i = 0; i < buffer_size; i = i + num_threads) { 41 | int offset_idx = i + thread_id; 42 | if (offset_idx < buffer_size) { 43 | buffer[offset_idx] = init_value; 44 | } 45 | } 46 | __syncthreads(); 47 | } 48 | 49 | template 50 | __device__ void copy_data(T *src_pt, T *dist_pt, int data_length, int num_threads, int thread_id) { 51 | __syncthreads(); 52 | for (int i = 0; i < data_length; i = i + num_threads) { 53 | int offset_idx = i + thread_id; 54 | if (offset_idx < data_length) { 55 | dist_pt[offset_idx] = src_pt[offset_idx]; 56 | } 57 | } 58 | __syncthreads(); 59 | } 60 | 61 | template 62 | __device__ void init_buffer_nonblocking(T init_value, T *buffer, int buffer_size, int num_threads, int thread_id) { 63 | for (int i = 0; i < buffer_size; i = i + num_threads) { 64 | int offset_idx = i + thread_id; 65 | if (offset_idx < buffer_size) { 66 | buffer[offset_idx] = init_value; 67 | } 68 | } 69 | } 70 | 71 | template 72 | __device__ void copy_data_nonblocking(T *src_pt, T *dist_pt, int data_length, int num_threads, int thread_id) { 73 | for (int i = 0; i < data_length; i = i + num_threads) { 74 | int offset_idx = i + thread_id; 75 | if (offset_idx < data_length) { 76 | dist_pt[offset_idx] = src_pt[offset_idx]; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp==3.9.3 2 | aiosignal==1.3.1 3 | async-timeout==4.0.3 4 | attrs==23.2.0 5 | blobfile==2.1.1 6 | Brotli @ file:///tmp/abs_ecyw11_7ze/croots/recipe/brotli-split_1659616059936/work 7 | certifi @ file:///croot/certifi_1707229174982/work/certifi 8 | charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work 9 | contourpy==1.1.1 10 | cycler==0.12.1 11 | datasets==2.18.0 12 | dill==0.3.8 13 | filelock @ file:///croot/filelock_1700591183607/work 14 | fonttools==4.50.0 15 | frozenlist==1.4.1 16 | fsspec==2024.2.0 17 | gmpy2 @ file:///tmp/build/80754af9/gmpy2_1645455532332/work 18 | h5py==3.10.0 19 | huggingface-hub==0.21.4 20 | idna @ file:///croot/idna_1666125576474/work 21 | imageio==2.34.0 22 | importlib_resources==6.4.0 23 | Jinja2 @ file:///croot/jinja2_1706733616596/work 24 | jsonpatch==1.33 25 | jsonpointer==2.4 26 | kiwisolver==1.4.5 27 | lazy_loader==0.3 28 | lxml==4.9.4 29 | MarkupSafe @ file:///croot/markupsafe_1704205993651/work 30 | matplotlib==3.7.5 31 | mkl-fft @ file:///croot/mkl_fft_1695058164594/work 32 | mkl-random @ file:///croot/mkl_random_1695059800811/work 33 | mkl-service==2.4.0 34 | mpi4py @ file:///croot/mpi4py_1671223370575/work 35 | mpmath @ file:///croot/mpmath_1690848262763/work 36 | multidict==6.0.5 37 | multiprocess==0.70.16 38 | networkx @ file:///croot/networkx_1690561992265/work 39 | numpy @ file:///work/mkl/numpy_and_numpy_base_1682953417311/work 40 | opencv-python==4.9.0.80 41 | packaging==24.0 42 | pandas==2.0.3 43 | pillow @ file:///croot/pillow_1707233021655/work 44 | pyarrow==15.0.2 45 | pyarrow-hotfix==0.6 46 | pycryptodomex==3.20.0 47 | pyparsing==3.1.2 48 | PySocks @ file:///tmp/build/80754af9/pysocks_1605305779399/work 49 | python-dateutil==2.9.0.post0 50 | pytz==2024.1 51 | PyWavelets==1.4.1 52 | PyYAML @ file:///croot/pyyaml_1698096049011/work 53 | regex==2023.12.25 54 | requests @ file:///croot/requests_1707355572290/work 55 | safetensors==0.4.2 56 | scikit-image==0.21.0 57 | scipy==1.10.1 58 | six==1.16.0 59 | sympy @ file:///croot/sympy_1701397643339/work 60 | tifffile==2023.7.10 61 | tokenizers==0.15.2 62 | torch==2.2.1 63 | torchaudio==2.2.1 64 | torchvision==0.17.1 65 | tornado==6.4 66 | tqdm==4.66.2 67 | transformers==4.39.1 68 | triton==2.2.0 69 | typing_extensions @ file:///croot/typing_extensions_1705599297034/work 70 | tzdata==2024.1 71 | urllib3 @ file:///croot/urllib3_1707770551213/work 72 | visdom==0.2.4 73 | websocket-client==1.7.0 74 | xxhash==3.4.1 75 | yarl==1.9.4 76 | zipp==3.18.1 77 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/convert_bert_original_tf_checkpoint_to_pytorch.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2018 The HuggingFace Inc. team. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | """Convert BERT checkpoint.""" 16 | 17 | 18 | import argparse 19 | 20 | import torch 21 | 22 | from transformers import BertConfig, BertForPreTraining, load_tf_weights_in_bert 23 | from transformers.utils import logging 24 | 25 | 26 | logging.set_verbosity_info() 27 | 28 | 29 | def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path): 30 | # Initialise PyTorch model 31 | config = BertConfig.from_json_file(bert_config_file) 32 | print(f"Building PyTorch model from configuration: {config}") 33 | model = BertForPreTraining(config) 34 | 35 | # Load weights from tf checkpoint 36 | load_tf_weights_in_bert(model, config, tf_checkpoint_path) 37 | 38 | # Save pytorch-model 39 | print(f"Save PyTorch model to {pytorch_dump_path}") 40 | torch.save(model.state_dict(), pytorch_dump_path) 41 | 42 | 43 | if __name__ == "__main__": 44 | parser = argparse.ArgumentParser() 45 | # Required parameters 46 | parser.add_argument( 47 | "--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path." 48 | ) 49 | parser.add_argument( 50 | "--bert_config_file", 51 | default=None, 52 | type=str, 53 | required=True, 54 | help=( 55 | "The config json file corresponding to the pre-trained BERT model. \n" 56 | "This specifies the model architecture." 57 | ), 58 | ) 59 | parser.add_argument( 60 | "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model." 61 | ) 62 | args = parser.parse_args() 63 | convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path) 64 | -------------------------------------------------------------------------------- /scripts/dataloader.py: -------------------------------------------------------------------------------- 1 | import h5py 2 | import json 3 | import numpy as np 4 | import os 5 | from torch.utils.data import Dataset, DataLoader 6 | import torch 7 | import torch.nn as nn 8 | import torch.nn.functional as F 9 | import numpy as np 10 | import pickle 11 | 12 | class CCDataset(Dataset): 13 | def __init__(self, data_folder, split='train'): 14 | self.image_file = os.path.join(data_folder,f'{split}_image_attention_pool.pickle') 15 | self.cation_file = os.path.join(data_folder,f'{split}_caption_encoded.json') 16 | self.split = split 17 | 18 | 19 | with open(self.cation_file, 'r') as f: 20 | self.caption_data = json.load(f) 21 | 22 | self.image_list = list(self.caption_data.keys()) 23 | 24 | with open(self.image_file, 'rb') as file: 25 | self.image_data = pickle.load(file) 26 | 27 | 28 | def __len__(self):#计数所有caption句子数目来作为dataset的长度 29 | if self.split == 'test': 30 | return len(self.caption_data) 31 | else: 32 | return sum(len(captions) for captions in self.caption_data.values()) 33 | # return len(self.caption_data) 34 | 35 | def __getitem__(self, idx): 36 | if self.split == 'test': 37 | img_idx = idx 38 | else: 39 | # img_idx = idx 40 | img_idx = idx//5 41 | image_key = self.image_list[img_idx] #图像文件名 42 | 43 | image_info = self.image_data[img_idx] 44 | 45 | image_before = np.transpose(image_info[image_key]['image_before'], (2, 0, 1)) 46 | image_after = np.transpose(image_info[image_key]['image_after'], (2, 0, 1)) 47 | 48 | # image_before =image_info[image_key]['feat_bef'] 49 | # image_after = image_info[image_key]['feat_aft'] 50 | 51 | 52 | if self.split == 'test': 53 | text_info = self.caption_data[image_key] 54 | return image_before,image_after,np.array(text_info),image_key 55 | else: 56 | sentence_count = 0 57 | for _, captions in self.caption_data.items(): 58 | if idx < sentence_count + len(captions): 59 | 60 | caption_idx = idx - sentence_count 61 | text_info = captions[caption_idx] 62 | break 63 | sentence_count += len(captions) 64 | 65 | # text_info = self.caption_data[image_key] 66 | return image_before,image_after, np.array(text_info),image_key 67 | 68 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/utils/model_parallel_utils.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2020 The HuggingFace Team. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | from math import ceil 17 | 18 | 19 | def assert_device_map(device_map, num_blocks): 20 | blocks = list(range(0, num_blocks)) 21 | 22 | device_map_blocks = [item for sublist in list(device_map.values()) for item in sublist] 23 | 24 | # Duplicate check 25 | duplicate_blocks = [] 26 | for i in device_map_blocks: 27 | if device_map_blocks.count(i) > 1 and i not in duplicate_blocks: 28 | duplicate_blocks.append(i) 29 | # Missing blocks 30 | missing_blocks = [i for i in blocks if i not in device_map_blocks] 31 | extra_blocks = [i for i in device_map_blocks if i not in blocks] 32 | 33 | if len(duplicate_blocks) != 0: 34 | raise ValueError( 35 | "Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device." 36 | " These attention blocks were specified more than once: " + str(duplicate_blocks) 37 | ) 38 | if len(missing_blocks) != 0: 39 | raise ValueError( 40 | "There are attention blocks for this model that are not specified in the device_map. Add these attention " 41 | "blocks to a device on the device_map: " + str(missing_blocks) 42 | ) 43 | if len(extra_blocks) != 0: 44 | raise ValueError( 45 | "The device_map contains more attention blocks than this model has. Remove these from the device_map:" 46 | + str(extra_blocks) 47 | ) 48 | 49 | 50 | def get_device_map(n_layers, devices): 51 | """Returns a dictionary of layers distributed evenly across all devices.""" 52 | layers = list(range(n_layers)) 53 | n_blocks = int(ceil(n_layers / len(devices))) 54 | layers_list = [layers[i : i + n_blocks] for i in range(0, n_layers, n_blocks)] 55 | 56 | return dict(zip(devices, layers_list)) 57 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/fp16_util.py: -------------------------------------------------------------------------------- 1 | """ 2 | Helpers to train with 16-bit precision. 3 | """ 4 | 5 | import torch.nn as nn 6 | from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors 7 | 8 | 9 | def convert_module_to_f16(l): 10 | """ 11 | Convert primitive modules to float16. 12 | """ 13 | if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Conv3d)): 14 | l.weight.data = l.weight.data.half() 15 | l.bias.data = l.bias.data.half() 16 | 17 | 18 | def convert_module_to_f32(l): 19 | """ 20 | Convert primitive modules to float32, undoing convert_module_to_f16(). 21 | """ 22 | if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Conv3d)): 23 | l.weight.data = l.weight.data.float() 24 | l.bias.data = l.bias.data.float() 25 | 26 | 27 | def make_master_params(model_params): 28 | """ 29 | Copy model parameters into a (differently-shaped) list of full-precision 30 | parameters. 31 | """ 32 | master_params = _flatten_dense_tensors( 33 | [param.detach().float() for param in model_params] 34 | ) 35 | master_params = nn.Parameter(master_params) 36 | master_params.requires_grad = True 37 | return [master_params] 38 | 39 | 40 | def model_grads_to_master_grads(model_params, master_params): 41 | """ 42 | Copy the gradients from the model parameters into the master parameters 43 | from make_master_params(). 44 | """ 45 | master_params[0].grad = _flatten_dense_tensors( 46 | [param.grad.data.detach().float() for param in model_params] 47 | ) 48 | 49 | 50 | def master_params_to_model_params(model_params, master_params): 51 | """ 52 | Copy the master parameter data back into the model parameters. 53 | """ 54 | # Without copying to a list, if a generator is passed, this will 55 | # silently not copy any parameters. 56 | model_params = list(model_params) 57 | 58 | for param, master_param in zip( 59 | model_params, unflatten_master_params(model_params, master_params) 60 | ): 61 | param.detach().copy_(master_param) 62 | 63 | 64 | def unflatten_master_params(model_params, master_params): 65 | """ 66 | Unflatten the master parameters to look like model_params. 67 | """ 68 | return _unflatten_dense_tensors(master_params[0].detach(), model_params) 69 | 70 | 71 | def zero_grad(model_params): 72 | for param in model_params: 73 | # Taken from https://pytorch.org/docs/stable/_modules/torch/optim/optimizer.html#Optimizer.add_param_group 74 | if param.grad is not None: 75 | param.grad.detach_() 76 | param.grad.zero_() 77 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/commands/download.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from argparse import ArgumentParser 16 | 17 | from . import BaseTransformersCLICommand 18 | 19 | 20 | def download_command_factory(args): 21 | return DownloadCommand(args.model, args.cache_dir, args.force, args.trust_remote_code) 22 | 23 | 24 | class DownloadCommand(BaseTransformersCLICommand): 25 | @staticmethod 26 | def register_subcommand(parser: ArgumentParser): 27 | download_parser = parser.add_parser("download") 28 | download_parser.add_argument( 29 | "--cache-dir", type=str, default=None, help="Path to location to store the models" 30 | ) 31 | download_parser.add_argument( 32 | "--force", action="store_true", help="Force the model to be download even if already in cache-dir" 33 | ) 34 | download_parser.add_argument( 35 | "--trust-remote-code", 36 | action="store_true", 37 | help="Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you've reviewed the code as it will execute on your local machine", 38 | ) 39 | download_parser.add_argument("model", type=str, help="Name of the model to download") 40 | download_parser.set_defaults(func=download_command_factory) 41 | 42 | def __init__(self, model: str, cache: str, force: bool, trust_remote_code: bool): 43 | self._model = model 44 | self._cache = cache 45 | self._force = force 46 | self._trust_remote_code = trust_remote_code 47 | 48 | def run(self): 49 | from ..models.auto import AutoModel, AutoTokenizer 50 | 51 | AutoModel.from_pretrained( 52 | self._model, cache_dir=self._cache, force_download=self._force, trust_remote_code=self._trust_remote_code 53 | ) 54 | AutoTokenizer.from_pretrained( 55 | self._model, cache_dir=self._cache, force_download=self._force, trust_remote_code=self._trust_remote_code 56 | ) 57 | -------------------------------------------------------------------------------- /img_preprocess.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pickle 3 | import numpy as np 4 | from PIL import Image 5 | from tqdm import tqdm 6 | import torch 7 | from torch import nn as nn 8 | from transformers import CLIPModel 9 | 10 | 11 | class image_pre: 12 | def __init__(self, default_data_path, default_data_processed_path, split="train"): 13 | self.device = "cuda" if torch.cuda.is_available() else "cpu" 14 | self.A_path = os.path.join(default_data_path, split, "A") 15 | self.B_path = os.path.join(default_data_path, split, "B") 16 | self.out_path = os.path.join(default_data_processed_path, split + '_image_attention_pool.pickle') 17 | self.split = split 18 | 19 | def process_images(self, folder_a_path, folder_b_path, output_pickle): 20 | images_a = [f for f in os.listdir(folder_a_path) if f.lower().endswith(('.png', '.jpg', '.jpeg'))] 21 | images_b = [f for f in os.listdir(folder_b_path) if f.lower().endswith(('.png', '.jpg', '.jpeg'))] 22 | 23 | # Extract the numeric part from the filenames and sort 24 | images_a.sort(key=lambda x: int(os.path.splitext(x)[0])) 25 | images_b.sort(key=lambda x: int(os.path.splitext(x)[0])) 26 | 27 | data = [] 28 | 29 | for image_name in tqdm(images_a): 30 | image_path_a = os.path.join(folder_a_path, image_name) 31 | image_path_b = os.path.join(folder_b_path, image_name) 32 | 33 | # Load images 34 | image_a = Image.open(image_path_a) 35 | image_b = Image.open(image_path_b) 36 | 37 | data_all = { 38 | image_name: { 39 | 'image_before': np.asarray(image_a).astype(np.float32), 40 | 'image_after': np.asarray(image_b).astype(np.float32) 41 | } 42 | } 43 | data.append(data_all) 44 | 45 | # Save data to pickle file 46 | with open(output_pickle, 'wb') as file: 47 | pickle.dump(data, file) 48 | 49 | def process_folders(self): 50 | self.process_images(self.A_path, self.B_path, self.out_path) 51 | print(f"The result will be saved at {self.out_path}") 52 | 53 | # Usage example 54 | default_data_path = 'data/images' 55 | default_data_processed_path = 'datasets' 56 | 57 | train_processor = image_pre(default_data_path, default_data_processed_path, split="train") 58 | train_processor.process_folders() 59 | 60 | test_processor = image_re(default_data_path, default_data_processed_path, split="test") 61 | test_processor.process_folders() 62 | 63 | val_processor = image_re(default_data_path, default_data_processed_path, split="val") 64 | val_processor.process_folders() 65 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/text_to_speech.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | import torch 18 | 19 | from ..models.speecht5 import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor 20 | from ..utils import is_datasets_available 21 | from .base import PipelineTool 22 | 23 | 24 | if is_datasets_available(): 25 | from datasets import load_dataset 26 | 27 | 28 | class TextToSpeechTool(PipelineTool): 29 | default_checkpoint = "microsoft/speecht5_tts" 30 | description = ( 31 | "This is a tool that reads an English text out loud. It takes an input named `text` which should contain the " 32 | "text to read (in English) and returns a waveform object containing the sound." 33 | ) 34 | name = "text_reader" 35 | pre_processor_class = SpeechT5Processor 36 | model_class = SpeechT5ForTextToSpeech 37 | post_processor_class = SpeechT5HifiGan 38 | 39 | inputs = ["text"] 40 | outputs = ["audio"] 41 | 42 | def setup(self): 43 | if self.post_processor is None: 44 | self.post_processor = "microsoft/speecht5_hifigan" 45 | super().setup() 46 | 47 | def encode(self, text, speaker_embeddings=None): 48 | inputs = self.pre_processor(text=text, return_tensors="pt", truncation=True) 49 | 50 | if speaker_embeddings is None: 51 | if not is_datasets_available(): 52 | raise ImportError("Datasets needs to be installed if not passing speaker embeddings.") 53 | 54 | embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation") 55 | speaker_embeddings = torch.tensor(embeddings_dataset[7305]["xvector"]).unsqueeze(0) 56 | 57 | return {"input_ids": inputs["input_ids"], "speaker_embeddings": speaker_embeddings} 58 | 59 | def forward(self, inputs): 60 | with torch.no_grad(): 61 | return self.model.generate_speech(**inputs) 62 | 63 | def decode(self, outputs): 64 | with torch.no_grad(): 65 | return self.post_processor(outputs).cpu().detach() 66 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/img_resnet.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import torch 4 | import torchvision 5 | #from improved_diffusion import dist_util 6 | 7 | import torch.nn as nn 8 | import torch.nn.functional as F 9 | import math 10 | from .dist_util import * 11 | 12 | 13 | class ResNet_Encoder(nn.Module): 14 | 15 | def __init__(self, NetType = 'resnet',encoded_image_size=14): 16 | super(ResNet_Encoder, self).__init__() 17 | # self.NetType = NetType 18 | self.enc_image_size = encoded_image_size 19 | self.mean = torch.tensor(np.array([0.485, 0.456, 0.406]).reshape(1, 3, 1, 1)).to(dev()) 20 | self.std = torch.tensor(np.array([0.229, 0.224, 0.224]).reshape(1, 3, 1, 1)).to(dev()) 21 | cnn = torchvision.models.resnet101(weights=torchvision.models.ResNet101_Weights.DEFAULT) 22 | layers = [ 23 | cnn.conv1, 24 | cnn.bn1, 25 | cnn.relu, 26 | cnn.maxpool, 27 | ] 28 | 29 | # 使用前model_stage个卷积块(最大为4)提取特征 30 | model_stage = 3 31 | for i in range(model_stage): 32 | name = 'layer%d' % (i + 1) 33 | layers.append(getattr(cnn, name)) 34 | self.net = nn.Sequential(*layers) 35 | 36 | # Resize image to fixed size to allow input images of variable size 37 | self.adaptive_pool = nn.AdaptiveAvgPool2d((encoded_image_size, encoded_image_size)) 38 | 39 | # self.linear = nn.Linear(1024,768) 40 | 41 | self.fine_tune() 42 | 43 | def forward(self, img): 44 | # print('img.size()',img.size()) 45 | img = (img / 255.0 - self.mean) / self.std 46 | 47 | out = self.net(img.float()) # (batch_size, 2048, image_size/32, image_size/32) 48 | out = self.adaptive_pool(out) # [batch_size, 2048/512, 8, 8] -> [batch_size, 2048/512, 14, 14] 49 | # print('img shape after resnet:',out.size()) 50 | bs,C,H,W = out.shape 51 | 52 | out = out.permute(0, 2, 3, 1).view(bs, H*W, C) 53 | # out = self.linear(out) 54 | # print('img shape after reshape:',out.size()) 55 | return out 56 | 57 | 58 | def fine_tune(self, fine_tune=True): 59 | """ 60 | Allow or prevent the computation of gradients for convolutional blocks 2 through 4 of the encoder. 61 | 62 | :param fine_tune: Allow? 63 | """ 64 | for p in self.net.parameters(): 65 | p.requires_grad = False 66 | # If fine-tuning, only fine-tune convolutional blocks 2 through 4 67 | for c in list(self.net.children())[5:]: # 68 | for p in c.parameters(): 69 | p.requires_grad = fine_tune 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /scripts/eval_func/meteor/meteor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Python wrapper for METEOR implementation, by Xinlei Chen 4 | # Acknowledge Michael Denkowski for the generous discussion and help 5 | 6 | import os 7 | import sys 8 | import subprocess 9 | import threading 10 | 11 | # Assumes meteor-1.5.jar is in the same directory as meteor.py. Change as needed. 12 | METEOR_JAR = 'meteor-1.5.jar' 13 | 14 | 15 | # print METEOR_JAR 16 | 17 | class Meteor: 18 | 19 | def __init__(self): 20 | self.env = os.environ 21 | self.env['LC_ALL'] = 'en_US.UTF_8' 22 | self.meteor_cmd = ['java', '-jar', '-Xmx2G', METEOR_JAR, \ 23 | '-', '-', '-stdio', '-l', 'en', '-norm'] 24 | self.meteor_p = subprocess.Popen(self.meteor_cmd, \ 25 | cwd=os.path.dirname(os.path.abspath(__file__)), \ 26 | stdin=subprocess.PIPE, \ 27 | stdout=subprocess.PIPE, \ 28 | stderr=subprocess.PIPE, 29 | env=self.env, universal_newlines=True, bufsize=1) 30 | # Used to guarantee thread safety 31 | self.lock = threading.Lock() 32 | 33 | def compute_score(self, gts, res): 34 | 35 | scores = [] 36 | 37 | eval_line = 'EVAL' 38 | self.lock.acquire() 39 | for i in range(len(res)): 40 | assert (len(res[i]) == 1) 41 | stat = self._stat(res[i][0], gts[i]) 42 | eval_line += ' ||| {}'.format(stat) 43 | 44 | # Send to METEOR 45 | self.meteor_p.stdin.write(eval_line + '\n') 46 | 47 | # Collect segment scores 48 | for i in range(len(res)): 49 | score = float(self.meteor_p.stdout.readline().strip()) 50 | scores.append(score) 51 | 52 | # Final score 53 | final_score = float(self.meteor_p.stdout.readline().strip()) 54 | self.lock.release() 55 | 56 | return final_score, scores 57 | 58 | def method(self): 59 | return "METEOR" 60 | 61 | def _stat(self, hypothesis_str, reference_list): 62 | # SCORE ||| reference 1 words ||| reference n words ||| hypothesis words 63 | hypothesis_str = hypothesis_str.replace('|||', '').replace(' ', ' ') 64 | score_line = ' ||| '.join(('SCORE', ' ||| '.join(reference_list), hypothesis_str)) 65 | self.meteor_p.stdin.write(score_line + '\n') 66 | return self.meteor_p.stdout.readline().strip() 67 | 68 | def __del__(self): 69 | self.lock.acquire() 70 | self.meteor_p.stdin.close() 71 | self.meteor_p.kill() 72 | self.meteor_p.wait() 73 | self.lock.release() -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/text_classification.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | import torch 18 | 19 | from ..models.auto import AutoModelForSequenceClassification, AutoTokenizer 20 | from .base import PipelineTool 21 | 22 | 23 | class TextClassificationTool(PipelineTool): 24 | """ 25 | Example: 26 | 27 | ```py 28 | from transformers.tools import TextClassificationTool 29 | 30 | classifier = TextClassificationTool() 31 | classifier("This is a super nice API!", labels=["positive", "negative"]) 32 | ``` 33 | """ 34 | 35 | default_checkpoint = "facebook/bart-large-mnli" 36 | description = ( 37 | "This is a tool that classifies an English text using provided labels. It takes two inputs: `text`, which " 38 | "should be the text to classify, and `labels`, which should be the list of labels to use for classification. " 39 | "It returns the most likely label in the list of provided `labels` for the input text." 40 | ) 41 | name = "text_classifier" 42 | pre_processor_class = AutoTokenizer 43 | model_class = AutoModelForSequenceClassification 44 | 45 | inputs = ["text", ["text"]] 46 | outputs = ["text"] 47 | 48 | def setup(self): 49 | super().setup() 50 | config = self.model.config 51 | self.entailment_id = -1 52 | for idx, label in config.id2label.items(): 53 | if label.lower().startswith("entail"): 54 | self.entailment_id = int(idx) 55 | if self.entailment_id == -1: 56 | raise ValueError("Could not determine the entailment ID from the model config, please pass it at init.") 57 | 58 | def encode(self, text, labels): 59 | self._labels = labels 60 | return self.pre_processor( 61 | [text] * len(labels), 62 | [f"This example is {label}" for label in labels], 63 | return_tensors="pt", 64 | padding="max_length", 65 | ) 66 | 67 | def decode(self, outputs): 68 | logits = outputs.logits 69 | label_id = torch.argmax(logits[:, 2]).item() 70 | return self._labels[label_id] 71 | -------------------------------------------------------------------------------- /word_encode.py: -------------------------------------------------------------------------------- 1 | import json 2 | from collections import Counter,defaultdict 3 | import os 4 | import torch.nn 5 | 6 | def word_processor(rawfile_path ='/Diffusion-RSCC/data/LevirCCcaptions.json',output_folder ='/Diffusion-RSCC/datasets'): 7 | 8 | # 读取raw caption文件 9 | with open(rawfile_path, 'r') as raw_file: 10 | data = json.load(raw_file) 11 | 12 | split_file_raw_dict = defaultdict(dict) 13 | 14 | max_sentence_length = 0 15 | word_freq = Counter() 16 | for item in data['images']: 17 | captions = [] 18 | for sentence in item['sentences']: 19 | tokens = sentence['tokens'] 20 | word_freq.update(tokens) 21 | # if len(tokens) == 39: 22 | # print('tokens 39:',tokens) 23 | max_sentence_length = max(max_sentence_length, len(tokens)) 24 | captions.append(tokens) 25 | if len(captions) == 0: 26 | continue 27 | 28 | print('max caption length:',max_sentence_length) 29 | max_sentence_length += 2 30 | print('final max sentence length(with,)',max_sentence_length) 31 | words = [w for w in word_freq.keys()] 32 | word_map = {k: v + 1 for v, k in enumerate(words)} 33 | word_map[''] = len(word_map) + 1 34 | word_map[''] = len(word_map) + 1 35 | word_map[''] = len(word_map) + 1 36 | word_map[''] = 0 37 | 38 | 39 | # Save word map to a JSON 40 | with open(os.path.join(output_folder, 'vocab' + '.json'), 'w') as j: 41 | json.dump(word_map, j) 42 | 43 | 44 | for item in data['images']: 45 | filename = item['filename'] 46 | split = item['split'] 47 | sentences = item['sentences'] 48 | raw_list = [] 49 | 50 | for sentence in sentences: 51 | tokens = sentence['tokens'] 52 | tokens = [''] + tokens + [''] 53 | encoded_tokens = [word_map[word] for word in tokens] 54 | padded_encoded_tokens = encoded_tokens + [0] * (max_sentence_length - len(encoded_tokens)) 55 | 56 | raw_list.append(padded_encoded_tokens) 57 | split_file_raw_dict[split][filename] = raw_list 58 | 59 | for split, file_raw_dict in split_file_raw_dict.items(): 60 | output_filename = os.path.join(output_folder,f'{split}_caption_encoded.json') 61 | with open(output_filename, 'w') as output_file: 62 | json.dump(file_raw_dict, output_file, separators=(',', ':')) 63 | in_channel = 16 64 | model = torch.nn.Embedding(len(word_map), in_channel) 65 | print('initializing the random embeddings', model) 66 | torch.nn.init.normal_(model.weight) 67 | path_save = f'datasets/random_emb.torch' 68 | print(f'save the random encoder to datasets/random_emb.torch') 69 | torch.save(model.state_dict(), path_save) 70 | word_processor() 71 | 72 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | from typing import TYPE_CHECKING 18 | 19 | from ..utils import ( 20 | OptionalDependencyNotAvailable, 21 | _LazyModule, 22 | is_torch_available, 23 | ) 24 | 25 | 26 | _import_structure = { 27 | "agents": ["Agent", "AzureOpenAiAgent", "HfAgent", "LocalAgent", "OpenAiAgent"], 28 | "base": ["PipelineTool", "RemoteTool", "Tool", "launch_gradio_demo", "load_tool"], 29 | } 30 | 31 | try: 32 | if not is_torch_available(): 33 | raise OptionalDependencyNotAvailable() 34 | except OptionalDependencyNotAvailable: 35 | pass 36 | else: 37 | _import_structure["document_question_answering"] = ["DocumentQuestionAnsweringTool"] 38 | _import_structure["image_captioning"] = ["ImageCaptioningTool"] 39 | _import_structure["image_question_answering"] = ["ImageQuestionAnsweringTool"] 40 | _import_structure["image_segmentation"] = ["ImageSegmentationTool"] 41 | _import_structure["speech_to_text"] = ["SpeechToTextTool"] 42 | _import_structure["text_classification"] = ["TextClassificationTool"] 43 | _import_structure["text_question_answering"] = ["TextQuestionAnsweringTool"] 44 | _import_structure["text_summarization"] = ["TextSummarizationTool"] 45 | _import_structure["text_to_speech"] = ["TextToSpeechTool"] 46 | _import_structure["translation"] = ["TranslationTool"] 47 | 48 | if TYPE_CHECKING: 49 | from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent 50 | from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool 51 | 52 | try: 53 | if not is_torch_available(): 54 | raise OptionalDependencyNotAvailable() 55 | except OptionalDependencyNotAvailable: 56 | pass 57 | else: 58 | from .document_question_answering import DocumentQuestionAnsweringTool 59 | from .image_captioning import ImageCaptioningTool 60 | from .image_question_answering import ImageQuestionAnsweringTool 61 | from .image_segmentation import ImageSegmentationTool 62 | from .speech_to_text import SpeechToTextTool 63 | from .text_classification import TextClassificationTool 64 | from .text_question_answering import TextQuestionAnsweringTool 65 | from .text_summarization import TextSummarizationTool 66 | from .text_to_speech import TextToSpeechTool 67 | from .translation import TranslationTool 68 | else: 69 | import sys 70 | 71 | sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__) 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Diffusion-RSCC: Diffusion Probabilistic Model for Change Captioning in Remote Sensing Images 2 | > __Diffusion-RSCC: Diffusion Probabilistic Model for Change Captioning in Remote Sensing Images__ 3 | > Xiaofei Yu, Yitong Li, Jie Ma*, Chang Li*, Hanlin Wu [[paper](https://arxiv.org/abs/2405.12875)] 4 | 5 | ## Model Architecture 6 | The proposed Diffusion-RSCC consists of: 7 | - A **forward diffusion process** that adds noise to caption embeddings until they resemble Gaussian noise. 8 | - A **reverse denoising process** using a specially designed **Condition Denoiser**: 9 | - **Feature Extractor**: Pretrained ResNet101 to extract features from bi-temporal images. 10 | - **Cross-Mode Fusion (CMF)**: Integrates visual and textual modalities for precise alignment. 11 | - **Stacking Self-Attention (SSA)**: Refines cross-modal information for accurate conditional mean estimation. 12 | - The denoised latent vectors are converted into natural language captions. 13 | 14 | ![flowchart](https://github.com/user-attachments/assets/2bc99e09-b23b-416c-aa63-044a059be52f) 15 | 16 | ### Datasets 17 | #### LEVIR-CC 18 | - A large-scale RSICC dataset with 10,077 bi-temporal image pairs and 50,385 captions. 19 | - Covers multiple semantic change types: buildings, roads, vegetation, parking lots, water. 20 | - Resized images: 256×256. 21 | 22 | Download Source: 23 | -Thanks for the Dataset by Liu et. al:[[GitHub](https://github.com/Chen-Yang-Liu/LEVIR-CC-Dataset)]. 24 | Put the content of downloaded dataset under the folder 'data' 25 | ```python 26 | path to ./data: 27 | ├─LevirCCcaptions.json 28 | ├─images 29 | ├─train 30 | │ ├─A 31 | │ ├─B 32 | ├─val 33 | │ ├─A 34 | │ ├─B 35 | ├─test 36 | │ ├─A 37 | │ ├─B 38 | ``` 39 | #### DUBAI-CC 40 | - Contains 500 urban area image pairs with 2500 annotations for changes in roads, buildings, lakes, etc. 41 | - Resized into 256×256 in Diffusion-RSCC. 42 | - Focuses on urbanization and land cover changes over 10 years. 43 | 44 | 45 | ## Installation and Dependencies 46 | ```python 47 | git clone https://github.com/Fay-Y/Diffusion-RSCC 48 | cd Diffusion-RSCC 49 | conda create -n DiffusionRSCC_env python=3.8 50 | conda activate DiffusionRSCC_env 51 | pip install -r requirements.txt 52 | ``` 53 | ## Preparation 54 | Preprocess the raw captions and image pairs: 55 | ```python 56 | python word_encode.py 57 | python img_preprocess.py 58 | ``` 59 | 60 | ## Training 61 | To train the proposed Diffusion-RSCC, run the following command: 62 | ```python 63 | sh demo.sh 64 | ``` 65 | 66 | ## Testing 67 | To test, evaluate and visualize on the test dataset, run the following command 68 | ```python 69 | sh testlm.sh 70 | ``` 71 | 72 | ## Visualization 73 | ```python 74 | cd result 75 | ``` 76 | In the paper, the predicted captions are saved in folder "result". 77 | ## Prediction samples 78 | Prediction results in test set with 5 Ground Truth captions are partly shown below, proving the effectiveness of our model. 79 | 80 | 81 | 82 | 83 | 84 |
compare2compare1
85 | 86 | ## TODO 87 | - [ ] Release training logs and checkpoints 88 | - [ ] Support more RSICC datasets 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/tools/document_question_answering.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # Copyright 2023 The HuggingFace Inc. team. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | import re 18 | 19 | from ..models.auto import AutoProcessor 20 | from ..models.vision_encoder_decoder import VisionEncoderDecoderModel 21 | from ..utils import is_vision_available 22 | from .base import PipelineTool 23 | 24 | 25 | if is_vision_available(): 26 | from PIL import Image 27 | 28 | 29 | class DocumentQuestionAnsweringTool(PipelineTool): 30 | default_checkpoint = "naver-clova-ix/donut-base-finetuned-docvqa" 31 | description = ( 32 | "This is a tool that answers a question about an document (pdf). It takes an input named `document` which " 33 | "should be the document containing the information, as well as a `question` that is the question about the " 34 | "document. It returns a text that contains the answer to the question." 35 | ) 36 | name = "document_qa" 37 | pre_processor_class = AutoProcessor 38 | model_class = VisionEncoderDecoderModel 39 | 40 | inputs = ["image", "text"] 41 | outputs = ["text"] 42 | 43 | def __init__(self, *args, **kwargs): 44 | if not is_vision_available(): 45 | raise ValueError("Pillow must be installed to use the DocumentQuestionAnsweringTool.") 46 | 47 | super().__init__(*args, **kwargs) 48 | 49 | def encode(self, document: "Image", question: str): 50 | task_prompt = "{user_input}" 51 | prompt = task_prompt.replace("{user_input}", question) 52 | decoder_input_ids = self.pre_processor.tokenizer( 53 | prompt, add_special_tokens=False, return_tensors="pt" 54 | ).input_ids 55 | pixel_values = self.pre_processor(document, return_tensors="pt").pixel_values 56 | 57 | return {"decoder_input_ids": decoder_input_ids, "pixel_values": pixel_values} 58 | 59 | def forward(self, inputs): 60 | return self.model.generate( 61 | inputs["pixel_values"].to(self.device), 62 | decoder_input_ids=inputs["decoder_input_ids"].to(self.device), 63 | max_length=self.model.decoder.config.max_position_embeddings, 64 | early_stopping=True, 65 | pad_token_id=self.pre_processor.tokenizer.pad_token_id, 66 | eos_token_id=self.pre_processor.tokenizer.eos_token_id, 67 | use_cache=True, 68 | num_beams=1, 69 | bad_words_ids=[[self.pre_processor.tokenizer.unk_token_id]], 70 | return_dict_in_generate=True, 71 | ).sequences 72 | 73 | def decode(self, outputs): 74 | sequence = self.pre_processor.batch_decode(outputs)[0] 75 | sequence = sequence.replace(self.pre_processor.tokenizer.eos_token, "") 76 | sequence = sequence.replace(self.pre_processor.tokenizer.pad_token, "") 77 | sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token 78 | sequence = self.pre_processor.token2json(sequence) 79 | 80 | return sequence["answer"] 81 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/yoso/fast_lsh_cumulation_torch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fast_lsh_cumulation.h" 4 | #include "common_cuda.h" 5 | #include 6 | 7 | std::vector fast_hash( 8 | at::Tensor query_mask, 9 | at::Tensor query_vector, 10 | at::Tensor key_mask, 11 | at::Tensor key_vector, 12 | int num_hash_f, 13 | int hash_code_len, 14 | bool use_cuda, 15 | int version 16 | ) { 17 | return fast_hash_ver1_kernel( 18 | query_mask, 19 | query_vector, 20 | key_mask, 21 | key_vector, 22 | num_hash_f, 23 | hash_code_len, 24 | use_cuda 25 | ); 26 | } 27 | 28 | at::Tensor lsh_cumulation( 29 | at::Tensor query_mask, // [batch_size, num_query] 30 | at::Tensor query_hash_code, // [batch_size, num_query, num_hash_f] 31 | at::Tensor key_mask, // [batch_size, num_key] 32 | at::Tensor key_hash_code, // [batch_size, num_key, num_hash_f] 33 | at::Tensor value, // [batch_size, num_key, value_dim] 34 | int hashtable_capacity, 35 | bool use_cuda, 36 | int version 37 | ) { 38 | return lsh_cumulation_ver1_kernel( 39 | query_mask, 40 | query_hash_code, 41 | key_mask, 42 | key_hash_code, 43 | value, 44 | hashtable_capacity, 45 | use_cuda 46 | ); 47 | } 48 | 49 | at::Tensor lsh_weighted_cumulation( 50 | at::Tensor query_mask, // [batch_size, num_query] 51 | at::Tensor query_hash_code, // [batch_size, num_query, num_hash_f] 52 | at::Tensor query_weight, // [batch_size, num_query, weight_dim] 53 | at::Tensor key_mask, // [batch_size, num_key] 54 | at::Tensor key_hash_code, // [batch_size, num_key, num_hash_f] 55 | at::Tensor key_weight, // [batch_size, num_key, weight_dim] 56 | at::Tensor value, // [batch_size, num_key, value_dim] 57 | int hashtable_capacity, 58 | bool use_cuda, 59 | int version 60 | ) { 61 | if (version == 1) { 62 | return lsh_weighted_cumulation_ver1_kernel( 63 | query_mask, 64 | query_hash_code, 65 | query_weight, 66 | key_mask, 67 | key_hash_code, 68 | key_weight, 69 | value, 70 | hashtable_capacity, 71 | use_cuda 72 | ); 73 | } else if (version == 2) { 74 | return lsh_weighted_cumulation_ver2_kernel( 75 | query_mask, 76 | query_hash_code, 77 | query_weight, 78 | key_mask, 79 | key_hash_code, 80 | key_weight, 81 | value, 82 | hashtable_capacity, 83 | use_cuda 84 | ); 85 | } else if (version == 3) { 86 | return lsh_weighted_cumulation_ver3_kernel( 87 | query_mask, 88 | query_hash_code, 89 | query_weight, 90 | key_mask, 91 | key_hash_code, 92 | key_weight, 93 | value, 94 | hashtable_capacity, 95 | use_cuda 96 | ); 97 | } else if (version == 4) { 98 | return lsh_weighted_cumulation_ver4_kernel( 99 | query_mask, 100 | query_hash_code, 101 | query_weight, 102 | key_mask, 103 | key_hash_code, 104 | key_weight, 105 | value, 106 | hashtable_capacity, 107 | use_cuda 108 | ); 109 | } else { 110 | return lsh_weighted_cumulation_ver3_kernel( 111 | query_mask, 112 | query_hash_code, 113 | query_weight, 114 | key_mask, 115 | key_hash_code, 116 | key_weight, 117 | value, 118 | hashtable_capacity, 119 | use_cuda 120 | ); 121 | } 122 | } 123 | 124 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 125 | m.def("fast_hash", &fast_hash, "Fast Hash (CUDA)"); 126 | m.def("lsh_cumulation", &lsh_cumulation, "LSH Cumulation (CUDA)"); 127 | m.def("lsh_weighted_cumulation", &lsh_weighted_cumulation, "LSH Weighted Cumulation (CUDA)"); 128 | } 129 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/processors/xnli.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. 3 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | """ XNLI utils (dataset loading and evaluation)""" 17 | 18 | 19 | import os 20 | 21 | from ...utils import logging 22 | from .utils import DataProcessor, InputExample 23 | 24 | 25 | logger = logging.get_logger(__name__) 26 | 27 | 28 | class XnliProcessor(DataProcessor): 29 | """ 30 | Processor for the XNLI dataset. Adapted from 31 | https://github.com/google-research/bert/blob/f39e881b169b9d53bea03d2d341b31707a6c052b/run_classifier.py#L207 32 | """ 33 | 34 | def __init__(self, language, train_language=None): 35 | self.language = language 36 | self.train_language = train_language 37 | 38 | def get_train_examples(self, data_dir): 39 | """See base class.""" 40 | lg = self.language if self.train_language is None else self.train_language 41 | lines = self._read_tsv(os.path.join(data_dir, f"XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv")) 42 | examples = [] 43 | for i, line in enumerate(lines): 44 | if i == 0: 45 | continue 46 | guid = f"train-{i}" 47 | text_a = line[0] 48 | text_b = line[1] 49 | label = "contradiction" if line[2] == "contradictory" else line[2] 50 | if not isinstance(text_a, str): 51 | raise ValueError(f"Training input {text_a} is not a string") 52 | if not isinstance(text_b, str): 53 | raise ValueError(f"Training input {text_b} is not a string") 54 | if not isinstance(label, str): 55 | raise ValueError(f"Training label {label} is not a string") 56 | examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label)) 57 | return examples 58 | 59 | def get_test_examples(self, data_dir): 60 | """See base class.""" 61 | lines = self._read_tsv(os.path.join(data_dir, "XNLI-1.0/xnli.test.tsv")) 62 | examples = [] 63 | for i, line in enumerate(lines): 64 | if i == 0: 65 | continue 66 | language = line[0] 67 | if language != self.language: 68 | continue 69 | guid = f"test-{i}" 70 | text_a = line[6] 71 | text_b = line[7] 72 | label = line[1] 73 | if not isinstance(text_a, str): 74 | raise ValueError(f"Training input {text_a} is not a string") 75 | if not isinstance(text_b, str): 76 | raise ValueError(f"Training input {text_b} is not a string") 77 | if not isinstance(label, str): 78 | raise ValueError(f"Training label {label} is not a string") 79 | examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label)) 80 | return examples 81 | 82 | def get_labels(self): 83 | """See base class.""" 84 | return ["contradiction", "entailment", "neutral"] 85 | 86 | 87 | xnli_processors = { 88 | "xnli": XnliProcessor, 89 | } 90 | 91 | xnli_output_modes = { 92 | "xnli": "classification", 93 | } 94 | 95 | xnli_tasks_num_labels = { 96 | "xnli": 3, 97 | } 98 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/data/metrics/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import warnings 14 | 15 | from ...utils import is_sklearn_available, requires_backends 16 | 17 | 18 | if is_sklearn_available(): 19 | from scipy.stats import pearsonr, spearmanr 20 | from sklearn.metrics import f1_score, matthews_corrcoef 21 | 22 | 23 | DEPRECATION_WARNING = ( 24 | "This metric will be removed from the library soon, metrics should be handled with the 🤗 Evaluate " 25 | "library. You can have a look at this example script for pointers: " 26 | "https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py" 27 | ) 28 | 29 | 30 | def simple_accuracy(preds, labels): 31 | warnings.warn(DEPRECATION_WARNING, FutureWarning) 32 | requires_backends(simple_accuracy, "sklearn") 33 | return (preds == labels).mean() 34 | 35 | 36 | def acc_and_f1(preds, labels): 37 | warnings.warn(DEPRECATION_WARNING, FutureWarning) 38 | requires_backends(acc_and_f1, "sklearn") 39 | acc = simple_accuracy(preds, labels) 40 | f1 = f1_score(y_true=labels, y_pred=preds) 41 | return { 42 | "acc": acc, 43 | "f1": f1, 44 | "acc_and_f1": (acc + f1) / 2, 45 | } 46 | 47 | 48 | def pearson_and_spearman(preds, labels): 49 | warnings.warn(DEPRECATION_WARNING, FutureWarning) 50 | requires_backends(pearson_and_spearman, "sklearn") 51 | pearson_corr = pearsonr(preds, labels)[0] 52 | spearman_corr = spearmanr(preds, labels)[0] 53 | return { 54 | "pearson": pearson_corr, 55 | "spearmanr": spearman_corr, 56 | "corr": (pearson_corr + spearman_corr) / 2, 57 | } 58 | 59 | 60 | def glue_compute_metrics(task_name, preds, labels): 61 | warnings.warn(DEPRECATION_WARNING, FutureWarning) 62 | requires_backends(glue_compute_metrics, "sklearn") 63 | assert len(preds) == len(labels), f"Predictions and labels have mismatched lengths {len(preds)} and {len(labels)}" 64 | if task_name == "cola": 65 | return {"mcc": matthews_corrcoef(labels, preds)} 66 | elif task_name == "sst-2": 67 | return {"acc": simple_accuracy(preds, labels)} 68 | elif task_name == "mrpc": 69 | return acc_and_f1(preds, labels) 70 | elif task_name == "sts-b": 71 | return pearson_and_spearman(preds, labels) 72 | elif task_name == "qqp": 73 | return acc_and_f1(preds, labels) 74 | elif task_name == "mnli": 75 | return {"mnli/acc": simple_accuracy(preds, labels)} 76 | elif task_name == "mnli-mm": 77 | return {"mnli-mm/acc": simple_accuracy(preds, labels)} 78 | elif task_name == "qnli": 79 | return {"acc": simple_accuracy(preds, labels)} 80 | elif task_name == "rte": 81 | return {"acc": simple_accuracy(preds, labels)} 82 | elif task_name == "wnli": 83 | return {"acc": simple_accuracy(preds, labels)} 84 | elif task_name == "hans": 85 | return {"acc": simple_accuracy(preds, labels)} 86 | else: 87 | raise KeyError(task_name) 88 | 89 | 90 | def xnli_compute_metrics(task_name, preds, labels): 91 | warnings.warn(DEPRECATION_WARNING, FutureWarning) 92 | requires_backends(xnli_compute_metrics, "sklearn") 93 | if len(preds) != len(labels): 94 | raise ValueError(f"Predictions and labels have mismatched lengths {len(preds)} and {len(labels)}") 95 | if task_name == "xnli": 96 | return {"acc": simple_accuracy(preds, labels)} 97 | else: 98 | raise KeyError(task_name) 99 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/onnx/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from ctypes import c_float, sizeof 16 | from enum import Enum 17 | from typing import TYPE_CHECKING, Optional, Union 18 | 19 | 20 | if TYPE_CHECKING: 21 | from .. import AutoFeatureExtractor, AutoProcessor, AutoTokenizer # tests_ignore 22 | 23 | 24 | class ParameterFormat(Enum): 25 | Float = c_float 26 | 27 | @property 28 | def size(self) -> int: 29 | """ 30 | Number of byte required for this data type 31 | 32 | Returns: 33 | Integer > 0 34 | """ 35 | return sizeof(self.value) 36 | 37 | 38 | def compute_effective_axis_dimension(dimension: int, fixed_dimension: int, num_token_to_add: int = 0) -> int: 39 | """ 40 | 41 | Args: 42 | dimension: 43 | fixed_dimension: 44 | num_token_to_add: 45 | 46 | Returns: 47 | 48 | """ 49 | # < 0 is possible if using a dynamic axis 50 | if dimension <= 0: 51 | dimension = fixed_dimension 52 | 53 | dimension -= num_token_to_add 54 | return dimension 55 | 56 | 57 | def compute_serialized_parameters_size(num_parameters: int, dtype: ParameterFormat) -> int: 58 | """ 59 | Compute the size taken by all the parameters in the given the storage format when serializing the model 60 | 61 | Args: 62 | num_parameters: Number of parameters to be saved 63 | dtype: The data format each parameter will be saved 64 | 65 | Returns: 66 | Size (in byte) taken to save all the parameters 67 | """ 68 | return num_parameters * dtype.size 69 | 70 | 71 | def get_preprocessor(model_name: str) -> Optional[Union["AutoTokenizer", "AutoFeatureExtractor", "AutoProcessor"]]: 72 | """ 73 | Gets a preprocessor (tokenizer, feature extractor or processor) that is available for `model_name`. 74 | 75 | Args: 76 | model_name (`str`): Name of the model for which a preprocessor are loaded. 77 | 78 | Returns: 79 | `Optional[Union[AutoTokenizer, AutoFeatureExtractor, AutoProcessor]]`: 80 | If a processor is found, it is returned. Otherwise, if a tokenizer or a feature extractor exists, it is 81 | returned. If both a tokenizer and a feature extractor exist, an error is raised. The function returns 82 | `None` if no preprocessor is found. 83 | """ 84 | # Avoid circular imports by only importing this here. 85 | from .. import AutoFeatureExtractor, AutoProcessor, AutoTokenizer # tests_ignore 86 | 87 | try: 88 | return AutoProcessor.from_pretrained(model_name) 89 | except (ValueError, OSError, KeyError): 90 | tokenizer, feature_extractor = None, None 91 | try: 92 | tokenizer = AutoTokenizer.from_pretrained(model_name) 93 | except (OSError, KeyError): 94 | pass 95 | try: 96 | feature_extractor = AutoFeatureExtractor.from_pretrained(model_name) 97 | except (OSError, KeyError): 98 | pass 99 | 100 | if tokenizer is not None and feature_extractor is not None: 101 | raise ValueError( 102 | f"Couldn't auto-detect preprocessor for {model_name}. Found both a tokenizer and a feature extractor." 103 | ) 104 | elif tokenizer is None and feature_extractor is None: 105 | return None 106 | elif tokenizer is not None: 107 | return tokenizer 108 | else: 109 | return feature_extractor 110 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/kernels/rwkv/wkv_op.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ATen/ATen.h" 3 | typedef at::BFloat16 bf16; 4 | 5 | void cuda_forward(int B, int T, int C, float *w, float *u, float *k, float *v, float *y); 6 | void cuda_forward_bf16(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y); 7 | void cuda_forward_with_state(int B, int T, int C, float *w, float *u, float *k, float *v, float *y, float *s); 8 | void cuda_forward_with_state_bf16(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y, float *s); 9 | void cuda_backward(int B, int T, int C, float *w, float *u, float *k, float *v, float *y, float *gy, float *gw, float *gu, float *gk, float *gv); 10 | void cuda_backward_bf16(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y, bf16 *gy, bf16 *gw, bf16 *gu, bf16 *gk, bf16 *gv); 11 | 12 | void forward(torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y) { 13 | const int B = k.size(0); 14 | const int T = k.size(1); 15 | const int C = k.size(2); 16 | cuda_forward(B, T, C, w.data_ptr(), u.data_ptr(), k.data_ptr(), v.data_ptr(), y.data_ptr()); 17 | } 18 | void forward_bf16(torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y) { 19 | const int B = k.size(0); 20 | const int T = k.size(1); 21 | const int C = k.size(2); 22 | cuda_forward_bf16(B, T, C, w.data_ptr(), u.data_ptr(), k.data_ptr(), v.data_ptr(), y.data_ptr()); 23 | } 24 | void forward_with_state(torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y, torch::Tensor &s) { 25 | const int B = k.size(0); 26 | const int T = k.size(1); 27 | const int C = k.size(2); 28 | cuda_forward_with_state(B, T, C, w.data_ptr(), u.data_ptr(), k.data_ptr(), v.data_ptr(), y.data_ptr(), s.data_ptr()); 29 | } 30 | void forward_with_state_bf16(torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y, torch::Tensor &s) { 31 | const int B = k.size(0); 32 | const int T = k.size(1); 33 | const int C = k.size(2); 34 | cuda_forward_with_state_bf16(B, T, C, w.data_ptr(), u.data_ptr(), k.data_ptr(), v.data_ptr(), y.data_ptr(), s.data_ptr()); 35 | } 36 | void backward(torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y, torch::Tensor &gy, torch::Tensor &gw, torch::Tensor &gu, torch::Tensor &gk, torch::Tensor &gv) { 37 | const int B = k.size(0); 38 | const int T = k.size(1); 39 | const int C = k.size(2); 40 | cuda_backward(B, T, C, w.data_ptr(), u.data_ptr(), k.data_ptr(), v.data_ptr(), y.data_ptr(), gy.data_ptr(), gw.data_ptr(), gu.data_ptr(), gk.data_ptr(), gv.data_ptr()); 41 | } 42 | void backward_bf16(torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y, torch::Tensor &gy, torch::Tensor &gw, torch::Tensor &gu, torch::Tensor &gk, torch::Tensor &gv) { 43 | const int B = k.size(0); 44 | const int T = k.size(1); 45 | const int C = k.size(2); 46 | cuda_backward_bf16(B, T, C, w.data_ptr(), u.data_ptr(), k.data_ptr(), v.data_ptr(), y.data_ptr(), 47 | gy.data_ptr(), gw.data_ptr(), gu.data_ptr(), gk.data_ptr(), gv.data_ptr()); 48 | } 49 | 50 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 51 | m.def("forward", &forward, "wkv forward"); 52 | m.def("forward_bf16", &forward_bf16, "wkv forward bf16"); 53 | m.def("forward_with_state", &forward_with_state, "wkv forward with state"); 54 | m.def("forward_with_state_bf16", &forward_with_state_bf16, "wkv forward with state bf16"); 55 | m.def("backward", &backward, "wkv backward"); 56 | m.def("backward_bf16", &backward_bf16, "wkv backward bf16"); 57 | } 58 | 59 | TORCH_LIBRARY(wkv, m) { 60 | m.def("forward", forward); 61 | m.def("forward_bf16", forward_bf16); 62 | m.def("forward_with_state", forward_with_state); 63 | m.def("forward_with_state_bf16", forward_with_state_bf16); 64 | m.def("backward", backward); 65 | m.def("backward_bf16", backward_bf16); 66 | } 67 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/file_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The HuggingFace Team. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | File utilities: utilities related to download and cache models 16 | 17 | This module should not be update anymore and is only left for backward compatibility. 18 | """ 19 | 20 | from huggingface_hub import get_full_repo_name # for backward compatibility 21 | 22 | from . import __version__ 23 | 24 | # Backward compatibility imports, to make sure all those objects can be found in file_utils 25 | from .utils import ( 26 | CLOUDFRONT_DISTRIB_PREFIX, 27 | CONFIG_NAME, 28 | DISABLE_TELEMETRY, 29 | DUMMY_INPUTS, 30 | DUMMY_MASK, 31 | ENV_VARS_TRUE_AND_AUTO_VALUES, 32 | ENV_VARS_TRUE_VALUES, 33 | FEATURE_EXTRACTOR_NAME, 34 | FLAX_WEIGHTS_NAME, 35 | HF_MODULES_CACHE, 36 | HUGGINGFACE_CO_PREFIX, 37 | HUGGINGFACE_CO_RESOLVE_ENDPOINT, 38 | MODEL_CARD_NAME, 39 | MULTIPLE_CHOICE_DUMMY_INPUTS, 40 | PYTORCH_PRETRAINED_BERT_CACHE, 41 | PYTORCH_TRANSFORMERS_CACHE, 42 | S3_BUCKET_PREFIX, 43 | SENTENCEPIECE_UNDERLINE, 44 | SPIECE_UNDERLINE, 45 | TF2_WEIGHTS_NAME, 46 | TF_WEIGHTS_NAME, 47 | TORCH_FX_REQUIRED_VERSION, 48 | TRANSFORMERS_CACHE, 49 | TRANSFORMERS_DYNAMIC_MODULE_NAME, 50 | USE_JAX, 51 | USE_TF, 52 | USE_TORCH, 53 | WEIGHTS_INDEX_NAME, 54 | WEIGHTS_NAME, 55 | ContextManagers, 56 | DummyObject, 57 | EntryNotFoundError, 58 | ExplicitEnum, 59 | ModelOutput, 60 | PaddingStrategy, 61 | PushToHubMixin, 62 | RepositoryNotFoundError, 63 | RevisionNotFoundError, 64 | TensorType, 65 | _LazyModule, 66 | add_code_sample_docstrings, 67 | add_end_docstrings, 68 | add_start_docstrings, 69 | add_start_docstrings_to_model_forward, 70 | cached_property, 71 | copy_func, 72 | default_cache_path, 73 | define_sagemaker_information, 74 | get_cached_models, 75 | get_file_from_repo, 76 | get_torch_version, 77 | has_file, 78 | http_user_agent, 79 | is_apex_available, 80 | is_bs4_available, 81 | is_coloredlogs_available, 82 | is_datasets_available, 83 | is_detectron2_available, 84 | is_faiss_available, 85 | is_flax_available, 86 | is_ftfy_available, 87 | is_in_notebook, 88 | is_ipex_available, 89 | is_librosa_available, 90 | is_offline_mode, 91 | is_onnx_available, 92 | is_pandas_available, 93 | is_phonemizer_available, 94 | is_protobuf_available, 95 | is_psutil_available, 96 | is_py3nvml_available, 97 | is_pyctcdecode_available, 98 | is_pytesseract_available, 99 | is_pytorch_quantization_available, 100 | is_rjieba_available, 101 | is_sagemaker_dp_enabled, 102 | is_sagemaker_mp_enabled, 103 | is_scipy_available, 104 | is_sentencepiece_available, 105 | is_seqio_available, 106 | is_sklearn_available, 107 | is_soundfile_availble, 108 | is_spacy_available, 109 | is_speech_available, 110 | is_tensor, 111 | is_tensorflow_probability_available, 112 | is_tf2onnx_available, 113 | is_tf_available, 114 | is_timm_available, 115 | is_tokenizers_available, 116 | is_torch_available, 117 | is_torch_bf16_available, 118 | is_torch_cuda_available, 119 | is_torch_fx_available, 120 | is_torch_fx_proxy, 121 | is_torch_mps_available, 122 | is_torch_tf32_available, 123 | is_torch_tpu_available, 124 | is_torchaudio_available, 125 | is_training_run_on_sagemaker, 126 | is_vision_available, 127 | replace_return_docstrings, 128 | requires_backends, 129 | to_numpy, 130 | to_py_obj, 131 | torch_only_method, 132 | ) 133 | -------------------------------------------------------------------------------- /scripts/tree_helper.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import spacy, nltk 3 | from nltk.tree import Tree 4 | import numpy as np 5 | 6 | def collapse_unary_strip_pos(tree, strip_top=True): 7 | """Collapse unary chains and strip part of speech tags.""" 8 | 9 | def strip_pos(tree): 10 | if len(tree) == 1 and isinstance(tree[0], str): 11 | return tree[0] 12 | else: 13 | return nltk.tree.Tree(tree.label(), [strip_pos(child) for child in tree]) 14 | 15 | collapsed_tree = strip_pos(tree) 16 | collapsed_tree.collapse_unary(collapsePOS=True, joinChar="::") 17 | if collapsed_tree.label() in ("TOP", "ROOT", "S1", "VROOT"): 18 | if strip_top: 19 | if len(collapsed_tree) == 1: 20 | collapsed_tree = collapsed_tree[0] 21 | else: 22 | collapsed_tree.set_label("") 23 | elif len(collapsed_tree) == 1: 24 | collapsed_tree[0].set_label( 25 | collapsed_tree.label() + "::" + collapsed_tree[0].label()) 26 | collapsed_tree = collapsed_tree[0] 27 | return collapsed_tree 28 | 29 | def _get_labeled_spans(tree, spans_out, start): 30 | if isinstance(tree, str): 31 | return start + 1 32 | 33 | assert len(tree) > 1 or isinstance( 34 | tree[0], str 35 | ), "Must call collapse_unary_strip_pos first" 36 | end = start 37 | for child in tree: 38 | end = _get_labeled_spans(child, spans_out, end) 39 | # Spans are returned as closed intervals on both ends 40 | spans_out.append((start, end - 1, tree.label())) 41 | return end 42 | 43 | def get_labeled_spans(tree): 44 | """Converts a tree into a list of labeled spans. 45 | Args: 46 | tree: an nltk.tree.Tree object 47 | Returns: 48 | A list of (span_start, span_end, span_label) tuples. The start and end 49 | indices indicate the first and last words of the span (a closed 50 | interval). Unary chains are collapsed, so e.g. a (S (VP ...)) will 51 | result in a single span labeled "S+VP". 52 | """ 53 | tree = collapse_unary_strip_pos(tree) 54 | spans_out = [] 55 | _get_labeled_spans(tree, spans_out, start=0) 56 | return spans_out 57 | 58 | def padded_chart_from_spans(label_vocab, spans, ): 59 | num_words = 64 60 | chart = np.full((num_words, num_words), -100, dtype=int) 61 | # chart = np.tril(chart, -1) 62 | # Now all invalid entries are filled with -100, and valid entries with 0 63 | for start, end, label in spans: 64 | if label in label_vocab: 65 | chart[start, end] = label_vocab[label] 66 | return chart 67 | 68 | def chart_from_tree(label_vocab, tree, verbose=False): 69 | spans = get_labeled_spans(tree) 70 | num_words = len(tree.leaves()) 71 | chart = np.full((num_words, num_words), -100, dtype=int) 72 | chart = np.tril(chart, -1) 73 | # Now all invalid entries are filled with -100, and valid entries with 0 74 | # print(tree) 75 | for start, end, label in spans: 76 | # Previously unseen unary chains can occur in the dev/test sets. 77 | # For now, we ignore them and don't mark the corresponding chart 78 | # entry as a constituent. 79 | # print(start, end, label) 80 | if label in label_vocab: 81 | chart[start, end] = label_vocab[label] 82 | if not verbose: 83 | return chart 84 | else: 85 | return chart, spans 86 | 87 | def pad_charts(charts, padding_value=-100): 88 | """ 89 | Our input text format contains START and END, but the parse charts doesn't. 90 | NEED TO: update the charts, so that we include these two, and set their span label to 0. 91 | 92 | :param charts: 93 | :param padding_value: 94 | :return: 95 | """ 96 | max_len = 64 97 | padded_charts = torch.full( 98 | (len(charts), max_len, max_len), 99 | padding_value, 100 | ) 101 | padded_charts = np.tril(padded_charts, -1) 102 | # print(padded_charts[-2:], padded_charts.shape) 103 | # print(padded_charts[1]) 104 | for i, chart in enumerate(charts): 105 | # print(chart, len(chart), len(chart[0])) 106 | chart_size = len(chart) 107 | padded_charts[i, 1:chart_size+1, 1:chart_size+1] = chart 108 | 109 | # print(padded_charts[-2:], padded_charts.shape) 110 | return padded_charts -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/benchmark/benchmark_args.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2018 The HuggingFace Inc. team. 3 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | from dataclasses import dataclass, field 18 | from typing import Tuple 19 | 20 | from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends 21 | from .benchmark_args_utils import BenchmarkArguments 22 | 23 | 24 | if is_torch_available(): 25 | import torch 26 | 27 | if is_torch_tpu_available(check_device=False): 28 | import torch_xla.core.xla_model as xm 29 | 30 | 31 | logger = logging.get_logger(__name__) 32 | 33 | 34 | @dataclass 35 | class PyTorchBenchmarkArguments(BenchmarkArguments): 36 | deprecated_args = [ 37 | "no_inference", 38 | "no_cuda", 39 | "no_tpu", 40 | "no_speed", 41 | "no_memory", 42 | "no_env_print", 43 | "no_multi_process", 44 | ] 45 | 46 | def __init__(self, **kwargs): 47 | """ 48 | This __init__ is there for legacy code. When removing deprecated args completely, the class can simply be 49 | deleted 50 | """ 51 | for deprecated_arg in self.deprecated_args: 52 | if deprecated_arg in kwargs: 53 | positive_arg = deprecated_arg[3:] 54 | setattr(self, positive_arg, not kwargs.pop(deprecated_arg)) 55 | logger.warning( 56 | f"{deprecated_arg} is depreciated. Please use --no_{positive_arg} or" 57 | f" {positive_arg}={kwargs[positive_arg]}" 58 | ) 59 | 60 | self.torchscript = kwargs.pop("torchscript", self.torchscript) 61 | self.torch_xla_tpu_print_metrics = kwargs.pop("torch_xla_tpu_print_metrics", self.torch_xla_tpu_print_metrics) 62 | self.fp16_opt_level = kwargs.pop("fp16_opt_level", self.fp16_opt_level) 63 | super().__init__(**kwargs) 64 | 65 | torchscript: bool = field(default=False, metadata={"help": "Trace the models using torchscript"}) 66 | torch_xla_tpu_print_metrics: bool = field(default=False, metadata={"help": "Print Xla/PyTorch tpu metrics"}) 67 | fp16_opt_level: str = field( 68 | default="O1", 69 | metadata={ 70 | "help": ( 71 | "For fp16: Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. " 72 | "See details at https://nvidia.github.io/apex/amp.html" 73 | ) 74 | }, 75 | ) 76 | 77 | @cached_property 78 | def _setup_devices(self) -> Tuple["torch.device", int]: 79 | requires_backends(self, ["torch"]) 80 | logger.info("PyTorch: setting up devices") 81 | if not self.cuda: 82 | device = torch.device("cpu") 83 | n_gpu = 0 84 | elif is_torch_tpu_available(): 85 | device = xm.xla_device() 86 | n_gpu = 0 87 | else: 88 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 89 | n_gpu = torch.cuda.device_count() 90 | return device, n_gpu 91 | 92 | @property 93 | def is_tpu(self): 94 | return is_torch_tpu_available() and self.tpu 95 | 96 | @property 97 | def device_idx(self) -> int: 98 | requires_backends(self, ["torch"]) 99 | # TODO(PVP): currently only single GPU is supported 100 | return torch.cuda.current_device() 101 | 102 | @property 103 | def device(self) -> "torch.device": 104 | requires_backends(self, ["torch"]) 105 | return self._setup_devices[0] 106 | 107 | @property 108 | def n_gpu(self): 109 | requires_backends(self, ["torch"]) 110 | return self._setup_devices[1] 111 | 112 | @property 113 | def is_gpu(self): 114 | return self.n_gpu > 0 115 | -------------------------------------------------------------------------------- /scripts/improved_diffusion/transformerK/models/bert/convert_bert_pytorch_checkpoint_to_original_tf.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2018 The HuggingFace Inc. team. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Convert Huggingface Pytorch checkpoint to Tensorflow checkpoint.""" 17 | 18 | import argparse 19 | import os 20 | 21 | import numpy as np 22 | import tensorflow as tf 23 | import torch 24 | 25 | from transformers import BertModel 26 | 27 | 28 | def convert_pytorch_checkpoint_to_tf(model: BertModel, ckpt_dir: str, model_name: str): 29 | """ 30 | Args: 31 | model: BertModel Pytorch model instance to be converted 32 | ckpt_dir: Tensorflow model directory 33 | model_name: model name 34 | 35 | Currently supported HF models: 36 | 37 | - Y BertModel 38 | - N BertForMaskedLM 39 | - N BertForPreTraining 40 | - N BertForMultipleChoice 41 | - N BertForNextSentencePrediction 42 | - N BertForSequenceClassification 43 | - N BertForQuestionAnswering 44 | """ 45 | 46 | tensors_to_transpose = ("dense.weight", "attention.self.query", "attention.self.key", "attention.self.value") 47 | 48 | var_map = ( 49 | ("layer.", "layer_"), 50 | ("word_embeddings.weight", "word_embeddings"), 51 | ("position_embeddings.weight", "position_embeddings"), 52 | ("token_type_embeddings.weight", "token_type_embeddings"), 53 | (".", "/"), 54 | ("LayerNorm/weight", "LayerNorm/gamma"), 55 | ("LayerNorm/bias", "LayerNorm/beta"), 56 | ("weight", "kernel"), 57 | ) 58 | 59 | if not os.path.isdir(ckpt_dir): 60 | os.makedirs(ckpt_dir) 61 | 62 | state_dict = model.state_dict() 63 | 64 | def to_tf_var_name(name: str): 65 | for patt, repl in iter(var_map): 66 | name = name.replace(patt, repl) 67 | return f"bert/{name}" 68 | 69 | def create_tf_var(tensor: np.ndarray, name: str, session: tf.Session): 70 | tf_dtype = tf.dtypes.as_dtype(tensor.dtype) 71 | tf_var = tf.get_variable(dtype=tf_dtype, shape=tensor.shape, name=name, initializer=tf.zeros_initializer()) 72 | session.run(tf.variables_initializer([tf_var])) 73 | session.run(tf_var) 74 | return tf_var 75 | 76 | tf.reset_default_graph() 77 | with tf.Session() as session: 78 | for var_name in state_dict: 79 | tf_name = to_tf_var_name(var_name) 80 | torch_tensor = state_dict[var_name].numpy() 81 | if any(x in var_name for x in tensors_to_transpose): 82 | torch_tensor = torch_tensor.T 83 | tf_var = create_tf_var(tensor=torch_tensor, name=tf_name, session=session) 84 | tf.keras.backend.set_value(tf_var, torch_tensor) 85 | tf_weight = session.run(tf_var) 86 | print(f"Successfully created {tf_name}: {np.allclose(tf_weight, torch_tensor)}") 87 | 88 | saver = tf.train.Saver(tf.trainable_variables()) 89 | saver.save(session, os.path.join(ckpt_dir, model_name.replace("-", "_") + ".ckpt")) 90 | 91 | 92 | def main(raw_args=None): 93 | parser = argparse.ArgumentParser() 94 | parser.add_argument("--model_name", type=str, required=True, help="model name e.g. bert-base-uncased") 95 | parser.add_argument( 96 | "--cache_dir", type=str, default=None, required=False, help="Directory containing pytorch model" 97 | ) 98 | parser.add_argument("--pytorch_model_path", type=str, required=True, help="/path/to/.bin") 99 | parser.add_argument("--tf_cache_dir", type=str, required=True, help="Directory in which to save tensorflow model") 100 | args = parser.parse_args(raw_args) 101 | 102 | model = BertModel.from_pretrained( 103 | pretrained_model_name_or_path=args.model_name, 104 | state_dict=torch.load(args.pytorch_model_path), 105 | cache_dir=args.cache_dir, 106 | ) 107 | 108 | convert_pytorch_checkpoint_to_tf(model=model, ckpt_dir=args.tf_cache_dir, model_name=args.model_name) 109 | 110 | 111 | if __name__ == "__main__": 112 | main() 113 | -------------------------------------------------------------------------------- /scripts/eval_func/rouge/rouge.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | 5 | # File Name : rouge.py 6 | 7 | # 8 | 9 | # Description : Computes ROUGE-L metric as described by Lin and Hovey (2004) 10 | 11 | # 12 | 13 | # Creation Date : 2015-01-07 06:03 14 | 15 | # Author : Ramakrishna Vedantam 16 | 17 | 18 | import numpy as np 19 | 20 | import pdb 21 | 22 | 23 | def my_lcs(string, sub): 24 | """ 25 | 26 | Calculates longest common subsequence for a pair of tokenized strings 27 | 28 | :param string : list of str : tokens from a string split using whitespace 29 | 30 | :param sub : list of str : shorter string, also split using whitespace 31 | 32 | :returns: length (list of int): length of the longest common subsequence between the two strings 33 | 34 | 35 | 36 | Note: my_lcs only gives length of the longest common subsequence, not the actual LCS 37 | 38 | """ 39 | 40 | if (len(string) < len(sub)): 41 | sub, string = string, sub 42 | 43 | lengths = [[0 for i in range(0, len(sub) + 1)] for j in range(0, len(string) + 1)] 44 | 45 | for j in range(1, len(sub) + 1): 46 | 47 | for i in range(1, len(string) + 1): 48 | 49 | if (string[i - 1] == sub[j - 1]): 50 | 51 | lengths[i][j] = lengths[i - 1][j - 1] + 1 52 | 53 | else: 54 | 55 | lengths[i][j] = max(lengths[i - 1][j], lengths[i][j - 1]) 56 | 57 | return lengths[len(string)][len(sub)] 58 | 59 | 60 | class Rouge(): 61 | ''' 62 | 63 | Class for computing ROUGE-L score for a set of candidate sentences for the MS COCO test set 64 | 65 | 66 | 67 | ''' 68 | 69 | def __init__(self): 70 | 71 | # vrama91: updated the value below based on discussion with Hovey 72 | 73 | self.beta = 1.2 74 | 75 | def calc_score(self, candidate, refs): 76 | 77 | """ 78 | 79 | Compute ROUGE-L score given one candidate and references for an image 80 | 81 | :param candidate: str : candidate sentence to be evaluated 82 | 83 | :param refs: list of str : COCO reference sentences for the particular image to be evaluated 84 | 85 | :returns score: int (ROUGE-L score for the candidate evaluated against references) 86 | 87 | """ 88 | 89 | 90 | assert (len(candidate) == 1) 91 | 92 | assert (len(refs) > 0) 93 | 94 | prec = [] 95 | 96 | rec = [] 97 | 98 | # split into tokens 99 | 100 | token_c = candidate[0].split(" ") 101 | 102 | for reference in refs: 103 | # split into tokens 104 | hh =1 105 | 106 | token_r = reference.split(" ") 107 | 108 | # compute the longest common subsequence 109 | 110 | lcs = my_lcs(token_r, token_c) 111 | 112 | prec.append(lcs / float(len(token_c))) 113 | 114 | rec.append(lcs / float(len(token_r))) 115 | 116 | prec_max = max(prec) 117 | 118 | rec_max = max(rec) 119 | 120 | if (prec_max != 0 and rec_max != 0): 121 | 122 | score = ((1 + self.beta ** 2) * prec_max * rec_max) / float(rec_max + self.beta ** 2 * prec_max) 123 | 124 | else: 125 | 126 | score = 0.0 127 | 128 | return score 129 | 130 | def compute_score(self, references, hypotheses): 131 | 132 | """ 133 | 134 | Computes Rouge-L score given a set of reference and candidate sentences for the dataset 135 | 136 | Invoked by evaluate_captions.py 137 | 138 | :param hypo_for_image: dict : candidate / test sentences with "image name" key and "tokenized sentences" as values 139 | 140 | :param ref_for_image: dict : reference MS-COCO sentences with "image name" key and "tokenized sentences" as values 141 | 142 | :returns: average_score: float (mean ROUGE-L score computed by averaging scores for all the images) 143 | 144 | """ 145 | 146 | # assert (gts.keys() == res.keys()) 147 | # 148 | # imgIds = gts.keys() 149 | 150 | score = [] 151 | 152 | for i in range(len(hypotheses)): 153 | hypo = hypotheses[i] 154 | ref = references[i] 155 | 156 | score.append(self.calc_score(hypo, ref)) 157 | 158 | # Sanity check. 159 | 160 | assert (type(hypo) is list) 161 | 162 | assert (len(hypo) == 1) 163 | 164 | assert (type(ref) is list) 165 | 166 | assert (len(ref) > 0) 167 | 168 | average_score = np.mean(np.array(score)) 169 | 170 | return average_score, np.array(score) 171 | 172 | def method(self): 173 | 174 | return "Rouge" -------------------------------------------------------------------------------- /scripts/improved_diffusion/losses.py: -------------------------------------------------------------------------------- 1 | """ 2 | Helpers for various likelihood-based losses. These are ported from the original 3 | Ho et al. diffusion models codebase: 4 | https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/utils.py 5 | """ 6 | 7 | import numpy as np 8 | 9 | import torch as th 10 | 11 | 12 | def normal_kl(mean1, logvar1, mean2, logvar2): 13 | """ 14 | Compute the KL divergence between two gaussians. 15 | 16 | Shapes are automatically broadcasted, so batches can be compared to 17 | scalars, among other use cases. 18 | """ 19 | tensor = None 20 | for obj in (mean1, logvar1, mean2, logvar2): 21 | if isinstance(obj, th.Tensor): 22 | tensor = obj 23 | break 24 | assert tensor is not None, "at least one argument must be a Tensor" 25 | 26 | # Force variances to be Tensors. Broadcasting helps convert scalars to 27 | # Tensors, but it does not work for th.exp(). 28 | logvar1, logvar2 = [ 29 | x if isinstance(x, th.Tensor) else th.tensor(x).to(tensor) 30 | for x in (logvar1, logvar2) 31 | ] 32 | 33 | # print(logvar2.shape) 34 | # temp1 = 0.5 * (-1.0 + logvar2 - logvar1 + th.exp(logvar1 - logvar2)) 35 | # print(f'const = {temp1.mean()}, coef={(th.exp(-logvar2) * 0.5).mean()}, mse={((mean1 - mean2) ** 2).mean().item()}') 36 | 37 | return 0.5 * ( 38 | -1.0 39 | + logvar2 40 | - logvar1 41 | + th.exp(logvar1 - logvar2) 42 | + ((mean1 - mean2) ** 2) * th.exp(-logvar2) 43 | ) 44 | 45 | 46 | def approx_standard_normal_cdf(x): 47 | """ 48 | A fast approximation of the cumulative distribution function of the 49 | standard normal. 50 | """ 51 | return 0.5 * (1.0 + th.tanh(np.sqrt(2.0 / np.pi) * (x + 0.044715 * th.pow(x, 3)))) 52 | 53 | 54 | def discretized_gaussian_log_likelihood(x, *, means, log_scales): 55 | """ 56 | Compute the log-likelihood of a Gaussian distribution discretizing to a 57 | given image. 58 | 59 | :param x: the target images. It is assumed that this was uint8 values, 60 | rescaled to the range [-1, 1]. 61 | :param means: the Gaussian mean Tensor. 62 | :param log_scales: the Gaussian log stddev Tensor. 63 | :return: a tensor like x of log probabilities (in nats). 64 | """ 65 | assert x.shape == means.shape == log_scales.shape 66 | centered_x = x - means 67 | inv_stdv = th.exp(-log_scales) 68 | plus_in = inv_stdv * (centered_x + 1.0 / 255.0) 69 | cdf_plus = approx_standard_normal_cdf(plus_in) 70 | min_in = inv_stdv * (centered_x - 1.0 / 255.0) 71 | cdf_min = approx_standard_normal_cdf(min_in) 72 | log_cdf_plus = th.log(cdf_plus.clamp(min=1e-12)) 73 | log_one_minus_cdf_min = th.log((1.0 - cdf_min).clamp(min=1e-12)) 74 | cdf_delta = cdf_plus - cdf_min 75 | log_probs = th.where( 76 | x < -0.999, 77 | log_cdf_plus, 78 | th.where(x > 0.999, log_one_minus_cdf_min, th.log(cdf_delta.clamp(min=1e-12))), 79 | ) 80 | assert log_probs.shape == x.shape 81 | return log_probs 82 | 83 | def gaussian_density(x, *, means, log_scales): 84 | from torch.distributions import Normal 85 | normal_dist = Normal(means, log_scales.exp()) 86 | logp = normal_dist.log_prob(x) 87 | return logp 88 | 89 | 90 | def discretized_text_log_likelihood(x, *, means, log_scales): 91 | """ 92 | Compute the log-likelihood of a Gaussian distribution discretizing to a 93 | given image. 94 | 95 | :param x: the target images. It is assumed that this was uint8 values, 96 | rescaled to the range [-1, 1]. 97 | :param means: the Gaussian mean Tensor. 98 | :param log_scales: the Gaussian log stddev Tensor. 99 | :return: a tensor like x of log probabilities (in nats). 100 | """ 101 | print(x.shape, means.shape) 102 | # assert x.shape == means.shape == log_scales.shape 103 | print(x, means) 104 | centered_x = x - means 105 | inv_stdv = th.exp(-log_scales) 106 | plus_in = inv_stdv * (centered_x + 1.0 / 255.0) 107 | cdf_plus = approx_standard_normal_cdf(plus_in) 108 | min_in = inv_stdv * (centered_x - 1.0 / 255.0) 109 | cdf_min = approx_standard_normal_cdf(min_in) 110 | log_cdf_plus = th.log(cdf_plus.clamp(min=1e-12)) 111 | log_one_minus_cdf_min = th.log((1.0 - cdf_min).clamp(min=1e-12)) 112 | cdf_delta = cdf_plus - cdf_min 113 | log_probs = th.where( 114 | x < -0.999, 115 | log_cdf_plus, 116 | th.where(x > 0.999, log_one_minus_cdf_min, th.log(cdf_delta.clamp(min=1e-12))), 117 | ) 118 | assert log_probs.shape == x.shape 119 | return log_probs 120 | --------------------------------------------------------------------------------