From 1e6b546ea62225a7e1dcbdb2341e89e46c87775b Mon Sep 17 00:00:00 2001 From: cyyever Date: Tue, 8 Apr 2025 20:12:08 +0800 Subject: [PATCH] Use Python 3.9 syntax in tests (#37343) Signed-off-by: cyy --- tests/agents/test_agent_types.py | 1 - tests/agents/test_agents.py | 1 - .../test_document_question_answering.py | 1 - tests/agents/test_final_answer.py | 1 - tests/agents/test_image_question_answering.py | 1 - tests/agents/test_monitoring.py | 1 - tests/agents/test_python_interpreter.py | 1 - tests/agents/test_search.py | 1 - tests/agents/test_speech_to_text.py | 1 - tests/agents/test_text_to_speech.py | 1 - tests/agents/test_tools_common.py | 5 ++-- tests/agents/test_translation.py | 1 - tests/bettertransformer/test_integration.py | 1 - tests/deepspeed/test_deepspeed.py | 5 ++-- tests/extended/test_trainer_ext.py | 3 +-- tests/generation/test_beam_constraints.py | 1 - tests/generation/test_beam_search.py | 1 - tests/generation/test_configuration_utils.py | 1 - tests/generation/test_logits_process.py | 5 ++-- tests/generation/test_stopping_criteria.py | 1 - tests/generation/test_streamers.py | 1 - tests/generation/test_utils.py | 1 - tests/models/albert/test_modeling_albert.py | 1 - .../models/albert/test_modeling_tf_albert.py | 1 - .../models/albert/test_tokenization_albert.py | 1 - tests/models/align/test_modeling_align.py | 1 - tests/models/altclip/test_modeling_altclip.py | 1 - .../models/altclip/test_processor_altclip.py | 1 - .../models/aria/test_image_processing_aria.py | 1 - tests/models/aria/test_modeling_aria.py | 1 - tests/models/aria/test_processor_aria.py | 1 - ...xtraction_audio_spectrogram_transformer.py | 1 - ..._modeling_audio_spectrogram_transformer.py | 1 - tests/models/auto/test_configuration_auto.py | 1 - .../auto/test_feature_extraction_auto.py | 1 - .../models/auto/test_image_processing_auto.py | 1 - tests/models/auto/test_modeling_auto.py | 1 - tests/models/auto/test_modeling_tf_auto.py | 1 - tests/models/auto/test_processor_auto.py | 11 ++++----- tests/models/auto/test_tokenization_auto.py | 1 - .../autoformer/test_modeling_autoformer.py | 1 - .../aya_vision/test_modeling_aya_vision.py | 1 - .../aya_vision/test_processor_aya_vision.py | 1 - tests/models/bamba/test_modeling_bamba.py | 1 - tests/models/bark/test_modeling_bark.py | 1 - tests/models/bart/test_modeling_bart.py | 1 - tests/models/bart/test_modeling_flax_bart.py | 4 ++-- tests/models/bart/test_modeling_tf_bart.py | 1 - .../barthez/test_tokenization_barthez.py | 1 - .../bartpho/test_tokenization_bartpho.py | 1 - .../models/beit/test_image_processing_beit.py | 1 - tests/models/beit/test_modeling_beit.py | 1 - tests/models/bert/test_modeling_bert.py | 1 - tests/models/bert/test_modeling_tf_bert.py | 1 - tests/models/bert/test_tokenization_bert.py | 1 - .../test_modeling_bert_generation.py | 1 - .../test_tokenization_bert_generation.py | 1 - .../test_tokenization_bert_japanese.py | 1 - .../bertweet/test_tokenization_bertweet.py | 1 - .../models/big_bird/test_modeling_big_bird.py | 3 +-- .../big_bird/test_tokenization_big_bird.py | 1 - .../test_modeling_bigbird_pegasus.py | 1 - tests/models/biogpt/test_modeling_biogpt.py | 1 - .../models/biogpt/test_tokenization_biogpt.py | 1 - tests/models/bit/test_modeling_bit.py | 1 - .../blenderbot/test_modeling_blenderbot.py | 1 - .../test_modeling_flax_blenderbot.py | 4 ++-- .../blenderbot/test_modeling_tf_blenderbot.py | 1 - .../test_tokenization_blenderbot.py | 1 - .../test_modeling_blenderbot_small.py | 1 - .../test_modeling_flax_blenderbot_small.py | 4 ++-- .../test_modeling_tf_blenderbot_small.py | 1 - .../test_tokenization_blenderbot_small.py | 1 - .../models/blip/test_image_processing_blip.py | 1 - tests/models/blip/test_modeling_blip.py | 1 - tests/models/blip/test_modeling_blip_text.py | 1 - tests/models/blip/test_modeling_tf_blip.py | 1 - .../models/blip/test_modeling_tf_blip_text.py | 1 - tests/models/blip_2/test_modeling_blip_2.py | 1 - tests/models/bloom/test_modeling_bloom.py | 1 - .../models/bloom/test_modeling_flax_bloom.py | 4 ++-- tests/models/bloom/test_tokenization_bloom.py | 1 - .../test_image_processing_bridgetower.py | 9 ++++---- .../bridgetower/test_modeling_bridgetower.py | 1 - tests/models/bros/test_modeling_bros.py | 1 - tests/models/byt5/test_tokenization_byt5.py | 4 +--- .../camembert/test_modeling_camembert.py | 1 - .../camembert/test_modeling_tf_camembert.py | 1 - .../camembert/test_tokenization_camembert.py | 1 - tests/models/canine/test_modeling_canine.py | 4 +--- .../models/canine/test_tokenization_canine.py | 1 - .../test_image_processing_chameleon.py | 1 - .../chameleon/test_modeling_chameleon.py | 1 - .../chameleon/test_processor_chameleon.py | 1 - .../test_image_processing_chinese_clip.py | 1 - .../test_modeling_chinese_clip.py | 1 - .../clap/test_feature_extraction_clap.py | 1 - tests/models/clap/test_modeling_clap.py | 1 - .../models/clip/test_image_processing_clip.py | 1 - tests/models/clip/test_modeling_clip.py | 7 +++--- tests/models/clip/test_modeling_tf_clip.py | 1 - tests/models/clip/test_tokenization_clip.py | 1 - tests/models/clipseg/test_modeling_clipseg.py | 1 - .../clvp/test_feature_extraction_clvp.py | 1 - tests/models/clvp/test_modeling_clvp.py | 1 - tests/models/clvp/test_tokenization_clvp.py | 4 +--- .../test_tokenization_code_llama.py | 5 ++-- tests/models/codegen/test_modeling_codegen.py | 1 - .../codegen/test_tokenization_codegen.py | 1 - tests/models/cohere/test_modeling_cohere.py | 1 - .../models/cohere/test_tokenization_cohere.py | 1 - tests/models/cohere2/test_modeling_cohere2.py | 1 - tests/models/colpali/test_modeling_colpali.py | 1 - .../test_image_processing_conditional_detr.py | 9 ++++---- .../test_modeling_conditional_detr.py | 1 - .../models/convbert/test_modeling_convbert.py | 1 - .../convbert/test_modeling_tf_convbert.py | 1 - .../test_image_processing_convnext.py | 1 - .../models/convnext/test_modeling_convnext.py | 1 - .../convnext/test_modeling_tf_convnext.py | 4 +--- .../convnextv2/test_modeling_convnextv2.py | 1 - .../convnextv2/test_modeling_tf_convnextv2.py | 4 +--- tests/models/cpm/test_tokenization_cpm.py | 1 - tests/models/cpmant/test_modeling_cpmant.py | 1 - .../models/cpmant/test_tokenization_cpmant.py | 1 - tests/models/ctrl/test_modeling_ctrl.py | 1 - tests/models/ctrl/test_modeling_tf_ctrl.py | 1 - tests/models/ctrl/test_tokenization_ctrl.py | 1 - tests/models/cvt/test_modeling_cvt.py | 1 - .../models/dab_detr/test_modeling_dab_detr.py | 6 ++--- .../models/dac/test_feature_extraction_dac.py | 1 - tests/models/dac/test_modeling_dac.py | 18 +++++++-------- .../data2vec/test_modeling_data2vec_audio.py | 1 - .../data2vec/test_modeling_data2vec_text.py | 1 - .../data2vec/test_modeling_data2vec_vision.py | 1 - .../test_modeling_tf_data2vec_vision.py | 3 +-- tests/models/dbrx/test_modeling_dbrx.py | 1 - tests/models/deberta/test_modeling_deberta.py | 1 - .../deberta/test_modeling_tf_deberta.py | 1 - .../deberta/test_tokenization_deberta.py | 1 - .../deberta_v2/test_modeling_deberta_v2.py | 1 - .../deberta_v2/test_modeling_tf_deberta_v2.py | 1 - .../test_tokenization_deberta_v2.py | 1 - .../test_modeling_decision_transformer.py | 1 - .../deepseek_v3/test_modeling_deepseek_v3.py | 1 - .../test_image_processing_deformable_detr.py | 13 +++++------ .../test_modeling_deformable_detr.py | 6 ++--- .../models/deit/test_image_processing_deit.py | 1 - tests/models/deit/test_modeling_deit.py | 1 - tests/models/deit/test_modeling_tf_deit.py | 1 - .../test_modeling_depth_anything.py | 1 - .../test_image_processing_depth_pro.py | 1 - .../depth_pro/test_modeling_depth_pro.py | 1 - .../models/detr/test_image_processing_detr.py | 17 +++++++------- tests/models/detr/test_modeling_detr.py | 1 - .../diffllama/test_modeling_diffllama.py | 1 - tests/models/dinat/test_modeling_dinat.py | 1 - tests/models/dinov2/test_modeling_dinov2.py | 1 - .../dinov2/test_modeling_flax_dinov2.py | 1 - .../test_modeling_dinov2_with_registers.py | 1 - .../distilbert/test_modeling_distilbert.py | 1 - .../distilbert/test_modeling_tf_distilbert.py | 1 - .../test_tokenization_distilbert.py | 1 - tests/models/dit/test_modeling_dit.py | 1 - .../donut/test_image_processing_donut.py | 1 - .../models/donut/test_modeling_donut_swin.py | 1 - tests/models/donut/test_processor_donut.py | 1 - tests/models/dpr/test_modeling_dpr.py | 1 - tests/models/dpr/test_modeling_tf_dpr.py | 1 - tests/models/dpr/test_tokenization_dpr.py | 1 - tests/models/dpt/test_image_processing_dpt.py | 1 - tests/models/dpt/test_modeling_dpt.py | 1 - .../dpt/test_modeling_dpt_auto_backbone.py | 1 - tests/models/dpt/test_modeling_dpt_hybrid.py | 1 - .../test_image_processing_efficientnet.py | 1 - .../test_modeling_efficientnet.py | 1 - tests/models/electra/test_modeling_electra.py | 1 - .../electra/test_modeling_tf_electra.py | 1 - .../electra/test_tokenization_electra.py | 1 - tests/models/emu3/test_modeling_emu3.py | 1 - tests/models/emu3/test_processor_emu3.py | 1 - .../test_feature_extraction_encodec.py | 1 - tests/models/encodec/test_modeling_encodec.py | 1 - .../test_modeling_encoder_decoder.py | 1 - .../test_modeling_flax_encoder_decoder.py | 3 +-- .../test_modeling_tf_encoder_decoder.py | 3 +-- tests/models/ernie/test_modeling_ernie.py | 1 - tests/models/esm/test_modeling_esm.py | 1 - tests/models/esm/test_modeling_esmfold.py | 1 - tests/models/esm/test_modeling_tf_esm.py | 1 - tests/models/esm/test_tokenization_esm.py | 6 ++--- tests/models/falcon/test_modeling_falcon.py | 1 - .../test_modeling_falcon_mamba.py | 8 +++---- .../test_modeling_fastspeech2_conformer.py | 1 - ...test_tokenization_fastspeech2_conformer.py | 1 - .../models/flaubert/test_modeling_flaubert.py | 1 - .../flaubert/test_modeling_tf_flaubert.py | 1 - .../flaubert/test_tokenization_flaubert.py | 1 - .../flava/test_image_processing_flava.py | 1 - tests/models/flava/test_modeling_flava.py | 1 - tests/models/fnet/test_modeling_fnet.py | 6 ++--- tests/models/fnet/test_tokenization_fnet.py | 1 - .../models/focalnet/test_modeling_focalnet.py | 1 - tests/models/fsmt/test_modeling_fsmt.py | 3 +-- tests/models/fsmt/test_tokenization_fsmt.py | 1 - tests/models/funnel/test_modeling_funnel.py | 1 - .../models/funnel/test_modeling_tf_funnel.py | 1 - .../models/funnel/test_tokenization_funnel.py | 1 - tests/models/fuyu/test_modeling_fuyu.py | 1 - .../models/gemma/test_modeling_flax_gemma.py | 4 ++-- tests/models/gemma/test_modeling_gemma.py | 1 - tests/models/gemma/test_tokenization_gemma.py | 5 ++-- tests/models/gemma2/test_modeling_gemma2.py | 1 - .../gemma3/test_image_processing_gemma3.py | 1 - tests/models/gemma3/test_modeling_gemma3.py | 1 - tests/models/git/test_modeling_git.py | 1 - tests/models/glm/test_modeling_glm.py | 1 - .../models/glpn/test_image_processing_glpn.py | 1 - tests/models/glpn/test_modeling_glpn.py | 1 - .../test_image_processing_got_ocr2.py | 1 - .../models/got_ocr2/test_modeling_got_ocr2.py | 1 - tests/models/gpt2/test_modeling_flax_gpt2.py | 4 ++-- tests/models/gpt2/test_modeling_gpt2.py | 1 - tests/models/gpt2/test_modeling_tf_gpt2.py | 1 - tests/models/gpt2/test_tokenization_gpt2.py | 1 - .../gpt_bigcode/test_modeling_gpt_bigcode.py | 1 - .../gpt_neo/test_modeling_flax_gpt_neo.py | 4 ++-- tests/models/gpt_neo/test_modeling_gpt_neo.py | 1 - .../models/gpt_neox/test_modeling_gpt_neox.py | 1 - .../test_modeling_gpt_neox_japanese.py | 1 - .../test_tokenization_gpt_neox_japanese.py | 1 - .../gpt_sw3/test_tokenization_gpt_sw3.py | 1 - tests/models/gptj/test_modeling_flax_gptj.py | 4 ++-- tests/models/gptj/test_modeling_gptj.py | 1 - tests/models/gptj/test_modeling_tf_gptj.py | 1 - tests/models/granite/test_modeling_granite.py | 1 - .../granitemoe/test_modeling_granitemoe.py | 1 - .../test_modeling_granitemoeshared.py | 1 - .../test_image_processing_grounding_dino.py | 9 ++++---- .../test_modeling_grounding_dino.py | 1 - .../models/groupvit/test_modeling_groupvit.py | 1 - .../groupvit/test_modeling_tf_groupvit.py | 1 - tests/models/helium/test_modeling_helium.py | 1 - .../herbert/test_tokenization_herbert.py | 1 - tests/models/hiera/test_modeling_hiera.py | 6 ++--- tests/models/hubert/test_modeling_hubert.py | 1 - .../models/hubert/test_modeling_tf_hubert.py | 1 - tests/models/ibert/test_modeling_ibert.py | 1 - .../idefics/test_image_processing_idefics.py | 1 - tests/models/idefics/test_modeling_idefics.py | 1 - .../idefics/test_modeling_tf_idefics.py | 1 - .../test_image_processing_idefics2.py | 1 - .../models/idefics2/test_modeling_idefics2.py | 1 - .../idefics2/test_processor_idefics2.py | 1 - .../test_image_processing_idefics3.py | 1 - .../models/idefics3/test_modeling_idefics3.py | 1 - .../idefics3/test_processor_idefics3.py | 1 - tests/models/ijepa/test_modeling_ijepa.py | 1 - .../test_image_processing_imagegpt.py | 1 - .../models/imagegpt/test_modeling_imagegpt.py | 1 - .../models/informer/test_modeling_informer.py | 1 - .../test_modeling_instructblip.py | 1 - ...test_image_processing_instrictblipvideo.py | 1 - .../test_modeling_instructblipvideo.py | 1 - tests/models/jamba/test_modeling_jamba.py | 1 - tests/models/jetmoe/test_modeling_jetmoe.py | 1 - tests/models/kosmos2/test_modeling_kosmos2.py | 1 - .../models/kosmos2/test_processor_kosmos2.py | 1 - .../models/layoutlm/test_modeling_layoutlm.py | 1 - .../layoutlm/test_modeling_tf_layoutlm.py | 1 - .../layoutlm/test_tokenization_layoutlm.py | 1 - .../test_image_processing_layoutlmv2.py | 1 - .../layoutlmv2/test_modeling_layoutlmv2.py | 1 - .../layoutlmv2/test_processor_layoutlmv2.py | 3 +-- .../test_tokenization_layoutlmv2.py | 6 ++--- .../test_image_processing_layoutlmv3.py | 1 - .../layoutlmv3/test_modeling_layoutlmv3.py | 1 - .../layoutlmv3/test_modeling_tf_layoutlmv3.py | 1 - .../layoutlmv3/test_processor_layoutlmv3.py | 3 +-- .../test_tokenization_layoutlmv3.py | 6 ++--- .../layoutxlm/test_processor_layoutxlm.py | 3 +-- .../layoutxlm/test_tokenization_layoutxlm.py | 6 ++--- tests/models/led/test_modeling_led.py | 1 - tests/models/led/test_modeling_tf_led.py | 1 - .../levit/test_image_processing_levit.py | 1 - tests/models/levit/test_modeling_levit.py | 1 - tests/models/lilt/test_modeling_lilt.py | 1 - .../models/llama/test_modeling_flax_llama.py | 4 ++-- tests/models/llama/test_modeling_llama.py | 1 - tests/models/llama/test_tokenization_llama.py | 5 ++-- .../llama4/test_image_processing_llama4.py | 1 - tests/models/llama4/test_modeling_llama4.py | 1 - .../llava/test_image_processing_llava.py | 5 ++-- tests/models/llava/test_modeling_llava.py | 1 - .../test_image_processing_llava_next.py | 1 - .../llava_next/test_modeling_llava_next.py | 1 - .../test_image_processing_llava_next_video.py | 1 - .../test_modeling_llava_next_video.py | 1 - .../test_processor_llava_next_video.py | 1 - .../test_image_processing_llava_onevision.py | 1 - .../test_modeling_llava_onevision.py | 1 - .../longformer/test_modeling_longformer.py | 1 - .../longformer/test_modeling_tf_longformer.py | 1 - .../test_tokenization_longformer.py | 3 +-- .../longt5/test_modeling_flax_longt5.py | 3 +-- tests/models/longt5/test_modeling_longt5.py | 1 - tests/models/luke/test_modeling_luke.py | 1 - tests/models/luke/test_tokenization_luke.py | 8 +++---- tests/models/lxmert/test_modeling_lxmert.py | 1 - .../models/lxmert/test_modeling_tf_lxmert.py | 1 - .../models/lxmert/test_tokenization_lxmert.py | 1 - tests/models/m2m_100/test_modeling_m2m_100.py | 1 - tests/models/mamba/test_modeling_mamba.py | 8 +++---- tests/models/mamba2/test_modeling_mamba2.py | 6 ++--- .../marian/test_modeling_flax_marian.py | 4 ++-- tests/models/marian/test_modeling_marian.py | 1 - .../models/marian/test_modeling_tf_marian.py | 1 - .../models/marian/test_tokenization_marian.py | 1 - .../test_feature_extraction_markuplm.py | 1 - .../models/markuplm/test_modeling_markuplm.py | 1 - .../markuplm/test_processor_markuplm.py | 3 +-- .../markuplm/test_tokenization_markuplm.py | 6 ++--- .../test_image_processing_mask2former.py | 1 - .../mask2former/test_modeling_mask2former.py | 1 - .../test_image_processing_maskformer.py | 1 - .../maskformer/test_modeling_maskformer.py | 1 - .../test_modeling_maskformer_swin.py | 6 ++--- .../models/mbart/test_modeling_flax_mbart.py | 4 ++-- tests/models/mbart/test_modeling_mbart.py | 1 - tests/models/mbart/test_modeling_tf_mbart.py | 1 - .../test_modeling_megatron_bert.py | 2 +- .../test_modeling_megatron_gpt2.py | 1 - tests/models/mgp_str/test_modeling_mgp_str.py | 1 - .../models/mgp_str/test_processor_mgp_str.py | 1 - .../mgp_str/test_tokenization_mgp_str.py | 1 - tests/models/mimi/test_modeling_mimi.py | 1 - .../mistral/test_modeling_flax_mistral.py | 4 ++-- tests/models/mistral/test_modeling_mistral.py | 1 - .../mistral/test_modeling_tf_mistral.py | 1 - .../models/mistral3/test_modeling_mistral3.py | 1 - .../mistral3/test_processor_mistral3.py | 1 - tests/models/mixtral/test_modeling_mixtral.py | 1 - .../mllama/test_image_processing_mllama.py | 1 - tests/models/mllama/test_modeling_mllama.py | 1 - tests/models/mllama/test_processor_mllama.py | 1 - tests/models/mluke/test_tokenization_mluke.py | 6 ++--- .../mobilebert/test_modeling_mobilebert.py | 1 - .../mobilebert/test_modeling_tf_mobilebert.py | 1 - .../test_tokenization_mobilebert.py | 1 - .../test_image_processing_mobilenet_v1.py | 1 - .../test_modeling_mobilenet_v1.py | 1 - .../test_image_processing_mobilenet_v2.py | 1 - .../test_modeling_mobilenet_v2.py | 1 - .../test_image_processing_mobilevit.py | 1 - .../mobilevit/test_modeling_mobilevit.py | 1 - .../mobilevit/test_modeling_tf_mobilevit.py | 1 - .../mobilevitv2/test_modeling_mobilevitv2.py | 1 - .../modernbert/test_modeling_modernbert.py | 3 +-- .../moonshine/test_modeling_moonshine.py | 1 - tests/models/moshi/test_modeling_moshi.py | 1 - tests/models/moshi/test_tokenization_moshi.py | 1 - tests/models/mpnet/test_modeling_mpnet.py | 1 - tests/models/mpnet/test_modeling_tf_mpnet.py | 1 - tests/models/mpnet/test_tokenization_mpnet.py | 1 - tests/models/mpt/test_modeling_mpt.py | 1 - tests/models/mra/test_modeling_mra.py | 1 - tests/models/mt5/test_modeling_tf_mt5.py | 1 - .../models/musicgen/test_modeling_musicgen.py | 1 - ...test_feature_extraction_musicgen_melody.py | 1 - .../test_modeling_musicgen_melody.py | 1 - tests/models/mvp/test_modeling_mvp.py | 1 - tests/models/myt5/test_tokenization_myt5.py | 1 - .../models/nemotron/test_modeling_nemotron.py | 1 - .../models/nllb_moe/test_modeling_nllb_moe.py | 1 - .../nougat/test_image_processing_nougat.py | 1 - .../models/nougat/test_tokenization_nougat.py | 1 - .../test_modeling_nystromformer.py | 1 - tests/models/olmo/test_modeling_olmo.py | 1 - tests/models/olmo2/test_modeling_olmo2.py | 1 - tests/models/olmoe/test_modeling_olmoe.py | 1 - .../omdet_turbo/test_modeling_omdet_turbo.py | 1 - .../test_image_processing_oneformer.py | 1 - .../oneformer/test_modeling_oneformer.py | 1 - .../oneformer/test_processor_oneformer.py | 3 +-- tests/models/openai/test_modeling_openai.py | 1 - .../models/openai/test_modeling_tf_openai.py | 1 - .../models/openai/test_tokenization_openai.py | 1 - tests/models/opt/test_modeling_flax_opt.py | 4 ++-- tests/models/opt/test_modeling_opt.py | 1 - tests/models/opt/test_modeling_tf_opt.py | 1 - .../owlv2/test_image_processing_owlv2.py | 1 - tests/models/owlv2/test_modeling_owlv2.py | 1 - .../owlvit/test_image_processing_owlvit.py | 1 - tests/models/owlvit/test_modeling_owlvit.py | 1 - .../paligemma/test_modeling_paligemma.py | 1 - .../paligemma2/test_modeling_paligemma2.py | 1 - .../test_modeling_patchtsmixer.py | 7 +++--- .../models/patchtst/test_modeling_patchtst.py | 1 - .../pegasus/test_modeling_flax_pegasus.py | 5 ++-- tests/models/pegasus/test_modeling_pegasus.py | 1 - .../pegasus/test_modeling_tf_pegasus.py | 1 - .../pegasus_x/test_modeling_pegasus_x.py | 1 - .../perceiver/test_modeling_perceiver.py | 6 ++--- .../perceiver/test_tokenization_perceiver.py | 4 +--- .../persimmon/test_modeling_persimmon.py | 1 - tests/models/phi/test_modeling_phi.py | 1 - tests/models/phi3/test_modeling_phi3.py | 4 +--- .../test_modeling_phi4_multimodal.py | 1 - tests/models/phimoe/test_modeling_phimoe.py | 4 +--- .../phobert/test_tokenization_phobert.py | 1 - .../test_image_processing_pix2struct.py | 1 - .../pix2struct/test_modeling_pix2struct.py | 1 - .../pixtral/test_image_processing_pixtral.py | 1 - tests/models/pixtral/test_modeling_pixtral.py | 1 - tests/models/plbart/test_modeling_plbart.py | 1 - .../test_image_processing_poolformer.py | 1 - .../poolformer/test_modeling_poolformer.py | 1 - .../test_feature_extraction_pop2piano.py | 1 - .../pop2piano/test_modeling_pop2piano.py | 1 - .../pop2piano/test_tokenization_pop2piano.py | 1 - ..._image_processing_prompt_depth_anything.py | 1 - .../test_modeling_prompt_depth_anything.py | 1 - .../prophetnet/test_modeling_prophetnet.py | 1 - .../test_tokenization_prophetnet.py | 1 - tests/models/pvt/test_image_processing_pvt.py | 1 - tests/models/pvt/test_modeling_pvt.py | 1 - tests/models/pvt_v2/test_modeling_pvt_v2.py | 1 - tests/models/qwen2/test_modeling_qwen2.py | 1 - tests/models/qwen2/test_tokenization_qwen2.py | 1 - .../qwen2_5_vl/test_modeling_qwen2_5_vl.py | 1 - .../qwen2_audio/test_modeling_qwen2_audio.py | 1 - .../qwen2_moe/test_modeling_qwen2_moe.py | 1 - .../test_image_processing_qwen2_vl.py | 1 - .../models/qwen2_vl/test_modeling_qwen2_vl.py | 1 - tests/models/qwen3/test_modeling_qwen3.py | 1 - .../qwen3_moe/test_modeling_qwen3_moe.py | 1 - tests/models/rag/test_modeling_rag.py | 1 - .../test_modeling_recurrent_gemma.py | 1 - .../models/reformer/test_modeling_reformer.py | 1 - .../regnet/test_modeling_flax_regnet.py | 1 - tests/models/regnet/test_modeling_regnet.py | 1 - .../models/regnet/test_modeling_tf_regnet.py | 4 +--- tests/models/rembert/test_modeling_rembert.py | 1 - .../rembert/test_modeling_tf_rembert.py | 1 - .../rembert/test_tokenization_rembert.py | 1 - tests/models/resnet/test_modeling_resnet.py | 1 - .../models/resnet/test_modeling_tf_resnet.py | 1 - tests/models/roberta/test_modeling_roberta.py | 1 - .../roberta/test_modeling_tf_roberta.py | 1 - .../roberta/test_tokenization_roberta.py | 3 +-- .../test_modeling_roberta_prelayernorm.py | 1 - .../test_modeling_tf_roberta_prelayernorm.py | 1 - .../models/roc_bert/test_modeling_roc_bert.py | 1 - .../roc_bert/test_tokenization_roc_bert.py | 1 - .../models/roformer/test_modeling_roformer.py | 1 - .../roformer/test_modeling_tf_roformer.py | 1 - .../roformer/test_tokenization_roformer.py | 1 - .../rt_detr/test_image_processing_rt_detr.py | 8 +++---- .../rt_detr/test_modeling_rt_detr_resnet.py | 1 - tests/models/rwkv/test_modeling_rwkv.py | 3 +-- tests/models/sam/test_modeling_sam.py | 1 - tests/models/sam/test_modeling_tf_sam.py | 1 - .../test_feature_extraction_seamless_m4t.py | 1 - .../test_modeling_seamless_m4t.py | 1 - .../test_modeling_seamless_m4t_v2.py | 1 - .../test_image_processing_segformer.py | 1 - .../segformer/test_modeling_segformer.py | 1 - .../segformer/test_modeling_tf_segformer.py | 6 ++--- .../seggpt/test_image_processing_seggpt.py | 1 - tests/models/seggpt/test_modeling_seggpt.py | 1 - tests/models/sew/test_modeling_sew.py | 1 - tests/models/sew_d/test_modeling_sew_d.py | 1 - .../test_modeling_shieldgemma2.py | 1 - .../siglip/test_image_processing_siglip.py | 1 - tests/models/siglip/test_modeling_siglip.py | 1 - .../models/siglip/test_tokenization_siglip.py | 1 - .../siglip2/test_image_processing_siglip2.py | 1 - tests/models/siglip2/test_modeling_siglip2.py | 1 - .../smolvlm/test_image_processing_smolvlm.py | 1 - tests/models/smolvlm/test_modeling_smolvlm.py | 1 - .../models/smolvlm/test_processor_smolvlm.py | 1 - ...st_modeling_flax_speech_encoder_decoder.py | 3 +-- .../test_modeling_speech_encoder_decoder.py | 1 - .../test_feature_extraction_speech_to_text.py | 1 - .../test_modeling_speech_to_text.py | 1 - .../test_modeling_tf_speech_to_text.py | 1 - .../test_feature_extraction_speecht5.py | 1 - .../models/speecht5/test_modeling_speecht5.py | 1 - .../speecht5/test_tokenization_speecht5.py | 1 - .../models/splinter/test_modeling_splinter.py | 1 - .../splinter/test_tokenization_splinter.py | 1 - .../squeezebert/test_modeling_squeezebert.py | 1 - .../test_tokenization_squeezebert.py | 1 - .../models/stablelm/test_modeling_stablelm.py | 1 - .../starcoder2/test_modeling_starcoder2.py | 1 - .../superglue/test_modeling_superglue.py | 5 ++-- .../superpoint/test_modeling_superpoint.py | 3 +-- .../swiftformer/test_modeling_swiftformer.py | 1 - .../test_modeling_tf_swiftformer.py | 1 - tests/models/swin/test_modeling_swin.py | 1 - tests/models/swin/test_modeling_tf_swin.py | 1 - .../swin2sr/test_image_processing_swin2sr.py | 1 - tests/models/swin2sr/test_modeling_swin2sr.py | 1 - tests/models/swinv2/test_modeling_swinv2.py | 1 - .../test_modeling_switch_transformers.py | 1 - tests/models/t5/test_modeling_flax_t5.py | 3 +-- tests/models/t5/test_modeling_t5.py | 1 - tests/models/t5/test_modeling_tf_t5.py | 1 - tests/models/t5/test_tokenization_t5.py | 1 - .../test_modeling_table_transformer.py | 1 - tests/models/tapas/test_modeling_tapas.py | 1 - tests/models/tapas/test_modeling_tf_tapas.py | 1 - tests/models/tapas/test_tokenization_tapas.py | 6 ++--- .../textnet/test_image_processing_textnet.py | 1 - tests/models/textnet/test_modeling_textnet.py | 1 - .../test_modeling_time_series_transformer.py | 1 - .../timesformer/test_modeling_timesformer.py | 1 - .../test_modeling_timm_backbone.py | 1 - .../test_image_processing_timm_wrapper.py | 1 - .../test_modeling_timm_wrapper.py | 1 - tests/models/trocr/test_modeling_trocr.py | 1 - tests/models/tvp/test_image_processing_tvp.py | 13 +++++------ tests/models/tvp/test_modeling_tvp.py | 1 - tests/models/udop/test_modeling_udop.py | 1 - tests/models/udop/test_processor_udop.py | 3 +-- tests/models/udop/test_tokenization_udop.py | 6 ++--- tests/models/umt5/__init__.py | 1 - .../unispeech/test_modeling_unispeech.py | 1 - .../test_modeling_unispeech_sat.py | 1 - tests/models/upernet/test_modeling_upernet.py | 1 - .../test_image_processing_video_llava.py | 1 - .../video_llava/test_modeling_video_llava.py | 1 - .../test_image_processing_videomae.py | 1 - .../models/videomae/test_modeling_videomae.py | 1 - .../models/vilt/test_image_processing_vilt.py | 1 - tests/models/vilt/test_modeling_vilt.py | 1 - .../models/vipllava/test_modeling_vipllava.py | 1 - ...st_modeling_flax_vision_encoder_decoder.py | 3 +-- ...test_modeling_tf_vision_encoder_decoder.py | 3 +-- .../test_modeling_vision_encoder_decoder.py | 1 - ..._modeling_flax_vision_text_dual_encoder.py | 3 +-- ...st_modeling_tf_vision_text_dual_encoder.py | 3 +-- .../test_modeling_vision_text_dual_encoder.py | 3 +-- .../visual_bert/test_modeling_visual_bert.py | 1 - tests/models/vit/test_image_processing_vit.py | 1 - tests/models/vit/test_modeling_tf_vit.py | 1 - tests/models/vit/test_modeling_vit.py | 1 - .../vit_mae/test_modeling_tf_vit_mae.py | 1 - tests/models/vit_mae/test_modeling_vit_mae.py | 1 - tests/models/vit_msn/test_modeling_vit_msn.py | 1 - tests/models/vitdet/test_modeling_vitdet.py | 1 - .../test_image_processing_vitmatte.py | 1 - .../models/vitmatte/test_modeling_vitmatte.py | 1 - .../vitpose/test_image_processing_vitpose.py | 1 - tests/models/vitpose/test_modeling_vitpose.py | 1 - .../test_modeling_vitpose_backbone.py | 1 - tests/models/vits/test_modeling_vits.py | 6 ++--- tests/models/vits/test_tokenization_vits.py | 1 - .../vivit/test_image_processing_vivit.py | 1 - tests/models/vivit/test_modeling_vivit.py | 1 - .../test_feature_extraction_wav2vec2.py | 1 - .../wav2vec2/test_modeling_tf_wav2vec2.py | 1 - .../models/wav2vec2/test_modeling_wav2vec2.py | 1 - .../wav2vec2/test_tokenization_wav2vec2.py | 1 - .../test_modeling_wav2vec2_bert.py | 1 - .../test_modeling_wav2vec2_conformer.py | 1 - .../test_tokenization_wav2vec2_phoneme.py | 4 +--- tests/models/wavlm/test_modeling_wavlm.py | 1 - .../test_feature_extraction_whisper.py | 1 - .../whisper/test_modeling_flax_whisper.py | 1 - .../whisper/test_modeling_tf_whisper.py | 1 - tests/models/whisper/test_modeling_whisper.py | 1 - tests/models/x_clip/test_modeling_x_clip.py | 1 - tests/models/xglm/test_modeling_flax_xglm.py | 5 ++-- tests/models/xglm/test_modeling_tf_xglm.py | 1 - tests/models/xglm/test_modeling_xglm.py | 1 - tests/models/xglm/test_tokenization_xglm.py | 1 - tests/models/xlm/test_modeling_tf_xlm.py | 1 - tests/models/xlm/test_modeling_xlm.py | 1 - tests/models/xlm/test_tokenization_xlm.py | 1 - .../test_modeling_flax_xlm_roberta.py | 1 - .../test_modeling_tf_xlm_roberta.py | 1 - .../xlm_roberta/test_modeling_xlm_roberta.py | 1 - .../test_tokenization_xlm_roberta.py | 1 - .../test_modeling_xlm_roberta_xl.py | 1 - tests/models/xlnet/test_modeling_tf_xlnet.py | 1 - tests/models/xlnet/test_modeling_xlnet.py | 1 - tests/models/xlnet/test_tokenization_xlnet.py | 1 - tests/models/xmod/test_modeling_xmod.py | 1 - .../yolos/test_image_processing_yolos.py | 9 ++++---- tests/models/yolos/test_modeling_yolos.py | 1 - tests/models/yoso/test_modeling_yoso.py | 1 - tests/models/zamba/test_modeling_zamba.py | 1 - tests/models/zamba2/test_modeling_zamba2.py | 1 - .../test_image_processing_zoedepth.py | 1 - .../models/zoedepth/test_modeling_zoedepth.py | 1 - tests/optimization/test_optimization.py | 1 - .../peft_integration/test_peft_integration.py | 1 - tests/pipelines/test_pipelines_common.py | 6 ++--- .../test_pipelines_image_segmentation.py | 5 ++-- .../test_pipelines_mask_generation.py | 9 +++----- ...est_pipelines_visual_question_answering.py | 4 ++-- .../aqlm_integration/test_aqlm.py | 1 - tests/quantization/autoawq/test_awq.py | 1 - .../bitnet_integration/test_bitnet.py | 1 - tests/quantization/bnb/test_4bit.py | 1 - tests/quantization/bnb/test_mixed_int8.py | 1 - .../eetq_integration/test_eetq.py | 1 - .../fbgemm_fp8/test_fbgemm_fp8.py | 1 - .../quantization/finegrained_fp8/test_fp8.py | 1 - tests/quantization/ggml/test_ggml.py | 1 - tests/quantization/gptq/test_gptq.py | 1 - tests/quantization/higgs/test_higgs.py | 1 - tests/quantization/hqq/test_hqq.py | 1 - .../quanto_integration/test_quanto.py | 1 - .../quark_integration/test_quark.py | 1 - .../spqr_integration/test_spqr.py | 1 - .../torchao_integration/test_torchao.py | 1 - .../vptq_integration/test_vptq.py | 3 +-- tests/repo_utils/test_check_copies.py | 6 ++--- tests/repo_utils/test_get_test_info.py | 1 - tests/repo_utils/test_tests_fetcher.py | 18 +++++++-------- .../pytorch/run_glue_model_parallelism.py | 1 - tests/test_backbone_common.py | 1 - tests/test_configuration_common.py | 1 - tests/test_feature_extraction_common.py | 1 - tests/test_image_processing_common.py | 5 ++-- tests/test_image_transforms.py | 1 - tests/test_modeling_common.py | 10 ++++---- tests/test_modeling_flax_common.py | 11 ++++----- tests/test_modeling_tf_common.py | 4 +--- tests/test_pipeline_mixin.py | 1 - tests/test_processing_common.py | 1 - ...test_sequence_feature_extraction_common.py | 1 - tests/test_tokenization_common.py | 23 +++++++++---------- tests/tokenization/test_tokenization_fast.py | 1 - tests/tokenization/test_tokenization_utils.py | 1 - tests/trainer/test_trainer.py | 4 +--- tests/trainer/test_trainer_distributed.py | 3 +-- tests/trainer/test_trainer_fsdp.py | 3 +-- tests/trainer/test_trainer_seq2seq.py | 1 - tests/trainer/test_trainer_tpu.py | 3 +-- tests/trainer/test_trainer_utils.py | 1 - tests/utils/test_add_new_model_like.py | 2 +- tests/utils/test_audio_utils.py | 1 - tests/utils/test_cache_utils.py | 1 - tests/utils/test_chat_template_utils.py | 16 ++++++------- tests/utils/test_cli.py | 1 - tests/utils/test_configuration_utils.py | 1 - tests/utils/test_doc_samples.py | 9 ++++---- tests/utils/test_feature_extraction_utils.py | 1 - tests/utils/test_generic.py | 1 - tests/utils/test_hf_argparser.py | 22 +++++++++--------- tests/utils/test_hub_utils.py | 2 +- tests/utils/test_image_processing_utils.py | 1 - tests/utils/test_image_utils.py | 1 - tests/utils/test_model_card.py | 1 - tests/utils/test_model_output.py | 1 - tests/utils/test_modeling_rope_utils.py | 1 - tests/utils/test_modeling_tf_core.py | 1 - tests/utils/test_modeling_tf_utils.py | 5 ++-- tests/utils/test_modeling_utils.py | 9 ++++---- tests/utils/test_offline.py | 3 +-- tests/utils/test_processing_utils.py | 1 - tests/utils/test_skip_decorators.py | 1 - tests/utils/test_tokenization_utils.py | 1 - 666 files changed, 265 insertions(+), 946 deletions(-) diff --git a/tests/agents/test_agent_types.py b/tests/agents/test_agent_types.py index 0fb56417d5..48c58f016a 100644 --- a/tests/agents/test_agent_types.py +++ b/tests/agents/test_agent_types.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_agents.py b/tests/agents/test_agents.py index 4f24abbeed..9a3c8e7a9f 100644 --- a/tests/agents/test_agents.py +++ b/tests/agents/test_agents.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_document_question_answering.py b/tests/agents/test_document_question_answering.py index d135551084..ff5d13350c 100644 --- a/tests/agents/test_document_question_answering.py +++ b/tests/agents/test_document_question_answering.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_final_answer.py b/tests/agents/test_final_answer.py index 91bdd65e89..e7f5ba6a89 100644 --- a/tests/agents/test_final_answer.py +++ b/tests/agents/test_final_answer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_image_question_answering.py b/tests/agents/test_image_question_answering.py index 405933e78a..60e3a1895e 100644 --- a/tests/agents/test_image_question_answering.py +++ b/tests/agents/test_image_question_answering.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_monitoring.py b/tests/agents/test_monitoring.py index c35074270e..b7b6b346f7 100644 --- a/tests/agents/test_monitoring.py +++ b/tests/agents/test_monitoring.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_python_interpreter.py b/tests/agents/test_python_interpreter.py index 15e5ad7bb3..8f9e265879 100644 --- a/tests/agents/test_python_interpreter.py +++ b/tests/agents/test_python_interpreter.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_search.py b/tests/agents/test_search.py index 7e40e3ca29..99bb3f25cb 100644 --- a/tests/agents/test_search.py +++ b/tests/agents/test_search.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_speech_to_text.py b/tests/agents/test_speech_to_text.py index 3d6e9a3929..1c4c0a401c 100644 --- a/tests/agents/test_speech_to_text.py +++ b/tests/agents/test_speech_to_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_text_to_speech.py b/tests/agents/test_text_to_speech.py index d8ed9afcbf..60458066a9 100644 --- a/tests/agents/test_text_to_speech.py +++ b/tests/agents/test_text_to_speech.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/agents/test_tools_common.py b/tests/agents/test_tools_common.py index 8226e71098..96fbf23e73 100644 --- a/tests/agents/test_tools_common.py +++ b/tests/agents/test_tools_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,7 @@ # limitations under the License. import unittest from pathlib import Path -from typing import Dict, Union +from typing import Union import numpy as np import pytest @@ -35,7 +34,7 @@ if is_vision_available(): AUTHORIZED_TYPES = ["string", "boolean", "integer", "number", "audio", "image", "any"] -def create_inputs(tool_inputs: Dict[str, Dict[Union[str, type], str]]): +def create_inputs(tool_inputs: dict[str, dict[Union[str, type], str]]): inputs = {} for input_name, input_desc in tool_inputs.items(): diff --git a/tests/agents/test_translation.py b/tests/agents/test_translation.py index 9027dd1731..bd045b4335 100644 --- a/tests/agents/test_translation.py +++ b/tests/agents/test_translation.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/bettertransformer/test_integration.py b/tests/bettertransformer/test_integration.py index b123001f10..9a3d9c3721 100644 --- a/tests/bettertransformer/test_integration.py +++ b/tests/bettertransformer/test_integration.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/deepspeed/test_deepspeed.py b/tests/deepspeed/test_deepspeed.py index 11bea3c3aa..b5215c1e9f 100644 --- a/tests/deepspeed/test_deepspeed.py +++ b/tests/deepspeed/test_deepspeed.py @@ -13,7 +13,6 @@ # limitations under the License. import dataclasses -import io import itertools import json import os @@ -436,9 +435,9 @@ class TrainerIntegrationDeepSpeedWithCustomConfig(TestCasePlus): } # use self.get_config_dict(stage) to use these to ensure the original is not modified - with io.open(self.ds_config_file[ZERO2], "r", encoding="utf-8") as f: + with open(self.ds_config_file[ZERO2], encoding="utf-8") as f: config_zero2 = json.load(f) - with io.open(self.ds_config_file[ZERO3], "r", encoding="utf-8") as f: + with open(self.ds_config_file[ZERO3], encoding="utf-8") as f: config_zero3 = json.load(f) # The following setting slows things down, so don't enable it by default unless needed by a test. # It's in the file as a demo for users since we want everything to work out of the box even if slower. diff --git a/tests/extended/test_trainer_ext.py b/tests/extended/test_trainer_ext.py index 4f6cf7dffa..afa8be4b8f 100644 --- a/tests/extended/test_trainer_ext.py +++ b/tests/extended/test_trainer_ext.py @@ -17,7 +17,6 @@ import os import re import sys from pathlib import Path -from typing import Tuple from unittest.mock import patch from parameterized import parameterized @@ -186,7 +185,7 @@ class TestTrainerExt(TestCasePlus): def test_run_seq2seq_bnb(self): from transformers.training_args import OptimizerNames - def train_and_return_metrics(optim: str) -> Tuple[int, float]: + def train_and_return_metrics(optim: str) -> tuple[int, float]: extra_args = "--skip_memory_metrics 0" output_dir = self.run_trainer( diff --git a/tests/generation/test_beam_constraints.py b/tests/generation/test_beam_constraints.py index 7b884b99e7..7f92e48aca 100644 --- a/tests/generation/test_beam_constraints.py +++ b/tests/generation/test_beam_constraints.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/generation/test_beam_search.py b/tests/generation/test_beam_search.py index 8de0001950..bd791bbc8f 100644 --- a/tests/generation/test_beam_search.py +++ b/tests/generation/test_beam_search.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/generation/test_configuration_utils.py b/tests/generation/test_configuration_utils.py index ef8010074b..f4f9764f48 100644 --- a/tests/generation/test_configuration_utils.py +++ b/tests/generation/test_configuration_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/generation/test_logits_process.py b/tests/generation/test_logits_process.py index 9d7acdfcb5..2647e6677d 100644 --- a/tests/generation/test_logits_process.py +++ b/tests/generation/test_logits_process.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,7 @@ # limitations under the License. import unittest -from typing import List, Union +from typing import Union import numpy as np from parameterized import parameterized @@ -86,7 +85,7 @@ class LogitsProcessorTest(unittest.TestCase): self.assertFalse(torch.isinf(scores_before_min_length).any()) @parameterized.expand([(0,), ([0, 18],)]) - def test_new_min_length_dist_processor(self, eos_token_id: Union[int, List[int]]): + def test_new_min_length_dist_processor(self, eos_token_id: Union[int, list[int]]): vocab_size = 20 batch_size = 4 diff --git a/tests/generation/test_stopping_criteria.py b/tests/generation/test_stopping_criteria.py index 375c10c672..b258f0e82d 100644 --- a/tests/generation/test_stopping_criteria.py +++ b/tests/generation/test_stopping_criteria.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/generation/test_streamers.py b/tests/generation/test_streamers.py index 2b17b6a7c4..db81c0fd93 100644 --- a/tests/generation/test_streamers.py +++ b/tests/generation/test_streamers.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/generation/test_utils.py b/tests/generation/test_utils.py index a922f88d7c..e16d477335 100644 --- a/tests/generation/test_utils.py +++ b/tests/generation/test_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/albert/test_modeling_albert.py b/tests/models/albert/test_modeling_albert.py index 5665345f7d..349a809b07 100644 --- a/tests/models/albert/test_modeling_albert.py +++ b/tests/models/albert/test_modeling_albert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/albert/test_modeling_tf_albert.py b/tests/models/albert/test_modeling_tf_albert.py index a3dab618ee..339943de9e 100644 --- a/tests/models/albert/test_modeling_tf_albert.py +++ b/tests/models/albert/test_modeling_tf_albert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/albert/test_tokenization_albert.py b/tests/models/albert/test_tokenization_albert.py index 73022d5b02..403d3e86e6 100644 --- a/tests/models/albert/test_tokenization_albert.py +++ b/tests/models/albert/test_tokenization_albert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 Hugging Face inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/align/test_modeling_align.py b/tests/models/align/test_modeling_align.py index 08d4ea2210..5f147220da 100644 --- a/tests/models/align/test_modeling_align.py +++ b/tests/models/align/test_modeling_align.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/altclip/test_modeling_altclip.py b/tests/models/altclip/test_modeling_altclip.py index a111181b69..0ad5e5cb03 100755 --- a/tests/models/altclip/test_modeling_altclip.py +++ b/tests/models/altclip/test_modeling_altclip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/altclip/test_processor_altclip.py b/tests/models/altclip/test_processor_altclip.py index 5b290efb11..f9ac0398e1 100644 --- a/tests/models/altclip/test_processor_altclip.py +++ b/tests/models/altclip/test_processor_altclip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/aria/test_image_processing_aria.py b/tests/models/aria/test_image_processing_aria.py index 255903e407..29ce63e276 100644 --- a/tests/models/aria/test_image_processing_aria.py +++ b/tests/models/aria/test_image_processing_aria.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/aria/test_modeling_aria.py b/tests/models/aria/test_modeling_aria.py index 0545aa77b2..60716a51b2 100644 --- a/tests/models/aria/test_modeling_aria.py +++ b/tests/models/aria/test_modeling_aria.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/aria/test_processor_aria.py b/tests/models/aria/test_processor_aria.py index 679d2467b4..57833e7a6a 100644 --- a/tests/models/aria/test_processor_aria.py +++ b/tests/models/aria/test_processor_aria.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/audio_spectrogram_transformer/test_feature_extraction_audio_spectrogram_transformer.py b/tests/models/audio_spectrogram_transformer/test_feature_extraction_audio_spectrogram_transformer.py index 7455d5ff85..77c2ec6cd3 100644 --- a/tests/models/audio_spectrogram_transformer/test_feature_extraction_audio_spectrogram_transformer.py +++ b/tests/models/audio_spectrogram_transformer/test_feature_extraction_audio_spectrogram_transformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py b/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py index 169ba3e8ae..e9919d7dcd 100644 --- a/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py +++ b/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/auto/test_configuration_auto.py b/tests/models/auto/test_configuration_auto.py index 69f9029f90..cfcebf01b8 100644 --- a/tests/models/auto/test_configuration_auto.py +++ b/tests/models/auto/test_configuration_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019-present, the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/auto/test_feature_extraction_auto.py b/tests/models/auto/test_feature_extraction_auto.py index d36183a63c..b00d508c8b 100644 --- a/tests/models/auto/test_feature_extraction_auto.py +++ b/tests/models/auto/test_feature_extraction_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/auto/test_image_processing_auto.py b/tests/models/auto/test_image_processing_auto.py index 1becf25ae7..c31f93a377 100644 --- a/tests/models/auto/test_image_processing_auto.py +++ b/tests/models/auto/test_image_processing_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/auto/test_modeling_auto.py b/tests/models/auto/test_modeling_auto.py index 5766b4adae..67c14f0af8 100644 --- a/tests/models/auto/test_modeling_auto.py +++ b/tests/models/auto/test_modeling_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/auto/test_modeling_tf_auto.py b/tests/models/auto/test_modeling_tf_auto.py index a63d9fbe4c..3f2641fc76 100644 --- a/tests/models/auto/test_modeling_tf_auto.py +++ b/tests/models/auto/test_modeling_tf_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/auto/test_processor_auto.py b/tests/models/auto/test_processor_auto.py index f9d0fa6438..0f14c744c2 100644 --- a/tests/models/auto/test_processor_auto.py +++ b/tests/models/auto/test_processor_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -107,7 +106,7 @@ class AutoFeatureExtractorTest(unittest.TestCase): json.dump(config_dict, fp) # drop `processor_class` in tokenizer config - with open(os.path.join(tmpdirname, TOKENIZER_CONFIG_FILE), "r") as f: + with open(os.path.join(tmpdirname, TOKENIZER_CONFIG_FILE)) as f: config_dict = json.load(f) config_dict.pop("processor_class") @@ -130,7 +129,7 @@ class AutoFeatureExtractorTest(unittest.TestCase): if os.path.isfile(os.path.join(tmpdirname, PROCESSOR_NAME)): # drop `processor_class` in processor - with open(os.path.join(tmpdirname, PROCESSOR_NAME), "r") as f: + with open(os.path.join(tmpdirname, PROCESSOR_NAME)) as f: config_dict = json.load(f) config_dict.pop("processor_class") @@ -138,7 +137,7 @@ class AutoFeatureExtractorTest(unittest.TestCase): f.write(json.dumps(config_dict)) # drop `processor_class` in tokenizer - with open(os.path.join(tmpdirname, TOKENIZER_CONFIG_FILE), "r") as f: + with open(os.path.join(tmpdirname, TOKENIZER_CONFIG_FILE)) as f: config_dict = json.load(f) config_dict.pop("processor_class") @@ -161,7 +160,7 @@ class AutoFeatureExtractorTest(unittest.TestCase): if os.path.isfile(os.path.join(tmpdirname, PROCESSOR_NAME)): # drop `processor_class` in processor - with open(os.path.join(tmpdirname, PROCESSOR_NAME), "r") as f: + with open(os.path.join(tmpdirname, PROCESSOR_NAME)) as f: config_dict = json.load(f) config_dict.pop("processor_class") @@ -169,7 +168,7 @@ class AutoFeatureExtractorTest(unittest.TestCase): f.write(json.dumps(config_dict)) # drop `processor_class` in feature extractor - with open(os.path.join(tmpdirname, FEATURE_EXTRACTOR_NAME), "r") as f: + with open(os.path.join(tmpdirname, FEATURE_EXTRACTOR_NAME)) as f: config_dict = json.load(f) config_dict.pop("processor_class") diff --git a/tests/models/auto/test_tokenization_auto.py b/tests/models/auto/test_tokenization_auto.py index efae6555f7..af266cd34e 100644 --- a/tests/models/auto/test_tokenization_auto.py +++ b/tests/models/auto/test_tokenization_auto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/autoformer/test_modeling_autoformer.py b/tests/models/autoformer/test_modeling_autoformer.py index cca8f3b3ac..578977c00c 100644 --- a/tests/models/autoformer/test_modeling_autoformer.py +++ b/tests/models/autoformer/test_modeling_autoformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/aya_vision/test_modeling_aya_vision.py b/tests/models/aya_vision/test_modeling_aya_vision.py index 688086fa0f..b5ff4f15a8 100644 --- a/tests/models/aya_vision/test_modeling_aya_vision.py +++ b/tests/models/aya_vision/test_modeling_aya_vision.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/aya_vision/test_processor_aya_vision.py b/tests/models/aya_vision/test_processor_aya_vision.py index 8830f85c50..93632884f7 100644 --- a/tests/models/aya_vision/test_processor_aya_vision.py +++ b/tests/models/aya_vision/test_processor_aya_vision.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bamba/test_modeling_bamba.py b/tests/models/bamba/test_modeling_bamba.py index ca0f4c95ff..c0703f8490 100644 --- a/tests/models/bamba/test_modeling_bamba.py +++ b/tests/models/bamba/test_modeling_bamba.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bark/test_modeling_bark.py b/tests/models/bark/test_modeling_bark.py index b44c3d3f04..78f2dd1aee 100644 --- a/tests/models/bark/test_modeling_bark.py +++ b/tests/models/bark/test_modeling_bark.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bart/test_modeling_bart.py b/tests/models/bart/test_modeling_bart.py index 50c5cd37d0..d23de5faa3 100644 --- a/tests/models/bart/test_modeling_bart.py +++ b/tests/models/bart/test_modeling_bart.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bart/test_modeling_flax_bart.py b/tests/models/bart/test_modeling_flax_bart.py index df2c689133..118398d3df 100644 --- a/tests/models/bart/test_modeling_flax_bart.py +++ b/tests/models/bart/test_modeling_flax_bart.py @@ -179,7 +179,7 @@ class FlaxBartModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -225,7 +225,7 @@ class FlaxBartModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/bart/test_modeling_tf_bart.py b/tests/models/bart/test_modeling_tf_bart.py index e93ab44795..075487915d 100644 --- a/tests/models/bart/test_modeling_tf_bart.py +++ b/tests/models/bart/test_modeling_tf_bart.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/barthez/test_tokenization_barthez.py b/tests/models/barthez/test_tokenization_barthez.py index 86663ce60c..5df4131d73 100644 --- a/tests/models/barthez/test_tokenization_barthez.py +++ b/tests/models/barthez/test_tokenization_barthez.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Ecole Polytechnique and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bartpho/test_tokenization_bartpho.py b/tests/models/bartpho/test_tokenization_bartpho.py index 6eb05a17ac..3e9ac6d6af 100644 --- a/tests/models/bartpho/test_tokenization_bartpho.py +++ b/tests/models/bartpho/test_tokenization_bartpho.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/beit/test_image_processing_beit.py b/tests/models/beit/test_image_processing_beit.py index 58175c6fe1..48b6518a55 100644 --- a/tests/models/beit/test_image_processing_beit.py +++ b/tests/models/beit/test_image_processing_beit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/beit/test_modeling_beit.py b/tests/models/beit/test_modeling_beit.py index 99abd4fa24..10f9c0645b 100644 --- a/tests/models/beit/test_modeling_beit.py +++ b/tests/models/beit/test_modeling_beit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bert/test_modeling_bert.py b/tests/models/bert/test_modeling_bert.py index 9c8ee2a69e..20d7b60238 100644 --- a/tests/models/bert/test_modeling_bert.py +++ b/tests/models/bert/test_modeling_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bert/test_modeling_tf_bert.py b/tests/models/bert/test_modeling_tf_bert.py index a8f8b73477..fe3689c9f0 100644 --- a/tests/models/bert/test_modeling_tf_bert.py +++ b/tests/models/bert/test_modeling_tf_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bert/test_tokenization_bert.py b/tests/models/bert/test_tokenization_bert.py index c4392b306b..6da10d0fe3 100644 --- a/tests/models/bert/test_tokenization_bert.py +++ b/tests/models/bert/test_tokenization_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bert_generation/test_modeling_bert_generation.py b/tests/models/bert_generation/test_modeling_bert_generation.py index a78bd8c41c..04a774ae8b 100644 --- a/tests/models/bert_generation/test_modeling_bert_generation.py +++ b/tests/models/bert_generation/test_modeling_bert_generation.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bert_generation/test_tokenization_bert_generation.py b/tests/models/bert_generation/test_tokenization_bert_generation.py index 1569932d71..d1657bb7d4 100644 --- a/tests/models/bert_generation/test_tokenization_bert_generation.py +++ b/tests/models/bert_generation/test_tokenization_bert_generation.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bert_japanese/test_tokenization_bert_japanese.py b/tests/models/bert_japanese/test_tokenization_bert_japanese.py index 73020e7052..9ef630ea91 100644 --- a/tests/models/bert_japanese/test_tokenization_bert_japanese.py +++ b/tests/models/bert_japanese/test_tokenization_bert_japanese.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bertweet/test_tokenization_bertweet.py b/tests/models/bertweet/test_tokenization_bertweet.py index d0659bc95a..9d6381ae11 100644 --- a/tests/models/bertweet/test_tokenization_bertweet.py +++ b/tests/models/bertweet/test_tokenization_bertweet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Salesforce and HuggingFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/big_bird/test_modeling_big_bird.py b/tests/models/big_bird/test_modeling_big_bird.py index 762d6531b2..e43c076bec 100644 --- a/tests/models/big_bird/test_modeling_big_bird.py +++ b/tests/models/big_bird/test_modeling_big_bird.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -892,7 +891,7 @@ class BigBirdModelIntegrationTest(unittest.TestCase): ) target_end_logits = torch.tensor( - [[-12.1736, -8.8487, -14.8877, -11.6713, -15.1165, -12.2396, -7.6828, -15.4153, -12.2528, -14.3671, -12.3596, -7.4272, -14.9615, -13.6356, -11.7939, -9.9767, -14.8112, -8.9567, -15.8798, -11.5291, -9.4249, -14.7544, -7.9387, -16.2789, -8.9702, -15.3111, -11.5585, -7.9992, -4.1127, 10.3209, -8.3926, -10.2005], [-11.1375, -15.4027, -12.6861, -16.9884, -13.7093, -10.3560, -15.7228, -12.9290, -15.8519, -13.7953, -10.2460, -15.7198, -14.2078, -12.8477, -11.4861, -16.1017, -11.8900, -16.4488, -13.2959, -10.3980, -15.4874, -10.3539, -16.8263, -10.9973, -17.0344, -9.2751, -10.1196, -13.8907, -12.1025, -13.0628, -12.8530, -13.8173]], # noqa: E321 + [[-12.1736, -8.8487, -14.8877, -11.6713, -15.1165, -12.2396, -7.6828, -15.4153, -12.2528, -14.3671, -12.3596, -7.4272, -14.9615, -13.6356, -11.7939, -9.9767, -14.8112, -8.9567, -15.8798, -11.5291, -9.4249, -14.7544, -7.9387, -16.2789, -8.9702, -15.3111, -11.5585, -7.9992, -4.1127, 10.3209, -8.3926, -10.2005], [-11.1375, -15.4027, -12.6861, -16.9884, -13.7093, -10.3560, -15.7228, -12.9290, -15.8519, -13.7953, -10.2460, -15.7198, -14.2078, -12.8477, -11.4861, -16.1017, -11.8900, -16.4488, -13.2959, -10.3980, -15.4874, -10.3539, -16.8263, -10.9973, -17.0344, -9.2751, -10.1196, -13.8907, -12.1025, -13.0628, -12.8530, -13.8173]], device=torch_device, ) # fmt: on diff --git a/tests/models/big_bird/test_tokenization_big_bird.py b/tests/models/big_bird/test_tokenization_big_bird.py index f8fa29ba48..e1e170df11 100644 --- a/tests/models/big_bird/test_tokenization_big_bird.py +++ b/tests/models/big_bird/test_tokenization_big_bird.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py b/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py index c4752097e9..ecdde66786 100644 --- a/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py +++ b/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/biogpt/test_modeling_biogpt.py b/tests/models/biogpt/test_modeling_biogpt.py index 8d92f0a247..ec6c64b556 100644 --- a/tests/models/biogpt/test_modeling_biogpt.py +++ b/tests/models/biogpt/test_modeling_biogpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/biogpt/test_tokenization_biogpt.py b/tests/models/biogpt/test_tokenization_biogpt.py index 4a9c53a6d0..9a21977982 100644 --- a/tests/models/biogpt/test_tokenization_biogpt.py +++ b/tests/models/biogpt/test_tokenization_biogpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bit/test_modeling_bit.py b/tests/models/bit/test_modeling_bit.py index 31effc266d..b8e09fa409 100644 --- a/tests/models/bit/test_modeling_bit.py +++ b/tests/models/bit/test_modeling_bit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blenderbot/test_modeling_blenderbot.py b/tests/models/blenderbot/test_modeling_blenderbot.py index d12154b128..945506eeb3 100644 --- a/tests/models/blenderbot/test_modeling_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_blenderbot.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blenderbot/test_modeling_flax_blenderbot.py b/tests/models/blenderbot/test_modeling_flax_blenderbot.py index 09af037e9c..1d3f77ee38 100644 --- a/tests/models/blenderbot/test_modeling_flax_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_flax_blenderbot.py @@ -179,7 +179,7 @@ class FlaxBlenderbotModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -225,7 +225,7 @@ class FlaxBlenderbotModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/blenderbot/test_modeling_tf_blenderbot.py b/tests/models/blenderbot/test_modeling_tf_blenderbot.py index 37f944c3d8..435c37d5fc 100644 --- a/tests/models/blenderbot/test_modeling_tf_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_tf_blenderbot.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blenderbot/test_tokenization_blenderbot.py b/tests/models/blenderbot/test_tokenization_blenderbot.py index 70f55f9448..79fb8fe062 100644 --- a/tests/models/blenderbot/test_tokenization_blenderbot.py +++ b/tests/models/blenderbot/test_tokenization_blenderbot.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blenderbot_small/test_modeling_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_blenderbot_small.py index c2fcdd852d..8bdf116647 100644 --- a/tests/models/blenderbot_small/test_modeling_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_blenderbot_small.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py index 7818dd67c7..7d810feb8d 100644 --- a/tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_flax_blenderbot_small.py @@ -178,7 +178,7 @@ class FlaxBlenderbotSmallModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -224,7 +224,7 @@ class FlaxBlenderbotSmallModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py index f70637df2d..70cb580cd6 100644 --- a/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blenderbot_small/test_tokenization_blenderbot_small.py b/tests/models/blenderbot_small/test_tokenization_blenderbot_small.py index 286052558b..5e02357160 100644 --- a/tests/models/blenderbot_small/test_tokenization_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_tokenization_blenderbot_small.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blip/test_image_processing_blip.py b/tests/models/blip/test_image_processing_blip.py index 522824507f..419aafeb28 100644 --- a/tests/models/blip/test_image_processing_blip.py +++ b/tests/models/blip/test_image_processing_blip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blip/test_modeling_blip.py b/tests/models/blip/test_modeling_blip.py index 1bf594d3c9..61fee01cd3 100644 --- a/tests/models/blip/test_modeling_blip.py +++ b/tests/models/blip/test_modeling_blip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blip/test_modeling_blip_text.py b/tests/models/blip/test_modeling_blip_text.py index d6614c6a2f..f28219d25f 100644 --- a/tests/models/blip/test_modeling_blip_text.py +++ b/tests/models/blip/test_modeling_blip_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blip/test_modeling_tf_blip.py b/tests/models/blip/test_modeling_tf_blip.py index ed427af7ee..71269048a3 100644 --- a/tests/models/blip/test_modeling_tf_blip.py +++ b/tests/models/blip/test_modeling_tf_blip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blip/test_modeling_tf_blip_text.py b/tests/models/blip/test_modeling_tf_blip_text.py index 082473dfd5..757ce98eed 100644 --- a/tests/models/blip/test_modeling_tf_blip_text.py +++ b/tests/models/blip/test_modeling_tf_blip_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/blip_2/test_modeling_blip_2.py b/tests/models/blip_2/test_modeling_blip_2.py index a360cb98a4..76a9fdfe5f 100644 --- a/tests/models/blip_2/test_modeling_blip_2.py +++ b/tests/models/blip_2/test_modeling_blip_2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bloom/test_modeling_bloom.py b/tests/models/bloom/test_modeling_bloom.py index 62c45f65b1..014c0f2f58 100644 --- a/tests/models/bloom/test_modeling_bloom.py +++ b/tests/models/bloom/test_modeling_bloom.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bloom/test_modeling_flax_bloom.py b/tests/models/bloom/test_modeling_flax_bloom.py index 60b865a45f..77b30fe19e 100644 --- a/tests/models/bloom/test_modeling_flax_bloom.py +++ b/tests/models/bloom/test_modeling_flax_bloom.py @@ -128,7 +128,7 @@ class FlaxBloomModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -163,7 +163,7 @@ class FlaxBloomModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/bloom/test_tokenization_bloom.py b/tests/models/bloom/test_tokenization_bloom.py index e8e255f49c..bd1d123181 100644 --- a/tests/models/bloom/test_tokenization_bloom.py +++ b/tests/models/bloom/test_tokenization_bloom.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bridgetower/test_image_processing_bridgetower.py b/tests/models/bridgetower/test_image_processing_bridgetower.py index d70715c78a..b038969513 100644 --- a/tests/models/bridgetower/test_image_processing_bridgetower.py +++ b/tests/models/bridgetower/test_image_processing_bridgetower.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The Intel Labs Team Authors, The Microsoft Research Team Authors and HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,7 @@ import unittest -from typing import Dict, List, Optional, Union +from typing import Optional, Union import numpy as np @@ -36,14 +35,14 @@ class BridgeTowerImageProcessingTester: self, parent, do_resize: bool = True, - size: Dict[str, int] = None, + size: dict[str, int] = None, size_divisor: int = 32, do_rescale: bool = True, rescale_factor: Union[int, float] = 1 / 255, do_normalize: bool = True, do_center_crop: bool = True, - image_mean: Optional[Union[float, List[float]]] = [0.48145466, 0.4578275, 0.40821073], - image_std: Optional[Union[float, List[float]]] = [0.26862954, 0.26130258, 0.27577711], + image_mean: Optional[Union[float, list[float]]] = [0.48145466, 0.4578275, 0.40821073], + image_std: Optional[Union[float, list[float]]] = [0.26862954, 0.26130258, 0.27577711], do_pad: bool = True, batch_size=7, min_resolution=30, diff --git a/tests/models/bridgetower/test_modeling_bridgetower.py b/tests/models/bridgetower/test_modeling_bridgetower.py index bc6ff0d6e4..f74b647278 100644 --- a/tests/models/bridgetower/test_modeling_bridgetower.py +++ b/tests/models/bridgetower/test_modeling_bridgetower.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The Intel Labs Team Authors, The Microsoft Research Team Authors and HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/bros/test_modeling_bros.py b/tests/models/bros/test_modeling_bros.py index d3c11a6f36..3a80497caf 100644 --- a/tests/models/bros/test_modeling_bros.py +++ b/tests/models/bros/test_modeling_bros.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/byt5/test_tokenization_byt5.py b/tests/models/byt5/test_tokenization_byt5.py index 5024ff3abe..519d83694a 100644 --- a/tests/models/byt5/test_tokenization_byt5.py +++ b/tests/models/byt5/test_tokenization_byt5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Google T5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +19,6 @@ import shutil import tempfile import unittest from functools import lru_cache -from typing import Tuple from transformers import AddedToken, BatchEncoding, ByT5Tokenizer from transformers.utils import cached_property, is_tf_available, is_torch_available @@ -57,7 +55,7 @@ class ByT5TokenizationTest(TokenizerTesterMixin, unittest.TestCase): pretrained_name = pretrained_name or cls.tmpdirname return cls.tokenizer_class.from_pretrained(pretrained_name, **kwargs) - def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> Tuple[str, list]: + def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> tuple[str, list]: # XXX The default common tokenizer tests assume that every ID is decodable on its own. # This assumption is invalid for ByT5 because single bytes might not be # valid utf-8 (byte 128 for instance). diff --git a/tests/models/camembert/test_modeling_camembert.py b/tests/models/camembert/test_modeling_camembert.py index bf41c8a9ef..b77d063cce 100644 --- a/tests/models/camembert/test_modeling_camembert.py +++ b/tests/models/camembert/test_modeling_camembert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/camembert/test_modeling_tf_camembert.py b/tests/models/camembert/test_modeling_tf_camembert.py index 425bdbc4b0..f9f8ba61d0 100644 --- a/tests/models/camembert/test_modeling_tf_camembert.py +++ b/tests/models/camembert/test_modeling_tf_camembert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/camembert/test_tokenization_camembert.py b/tests/models/camembert/test_tokenization_camembert.py index 4e46df0eda..33a49b3395 100644 --- a/tests/models/camembert/test_tokenization_camembert.py +++ b/tests/models/camembert/test_tokenization_camembert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/canine/test_modeling_canine.py b/tests/models/canine/test_modeling_canine.py index 803e942d7a..94becd11af 100644 --- a/tests/models/canine/test_modeling_canine.py +++ b/tests/models/canine/test_modeling_canine.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ """Testing suite for the PyTorch CANINE model.""" import unittest -from typing import List, Tuple from transformers import CanineConfig, is_torch_available from transformers.testing_utils import require_torch, slow, torch_device @@ -383,7 +381,7 @@ class CanineModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: diff --git a/tests/models/canine/test_tokenization_canine.py b/tests/models/canine/test_tokenization_canine.py index e2efc99ca9..6bcb54e33f 100644 --- a/tests/models/canine/test_tokenization_canine.py +++ b/tests/models/canine/test_tokenization_canine.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 Google AI and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/chameleon/test_image_processing_chameleon.py b/tests/models/chameleon/test_image_processing_chameleon.py index 1948e58f9f..fcbd7b46d5 100644 --- a/tests/models/chameleon/test_image_processing_chameleon.py +++ b/tests/models/chameleon/test_image_processing_chameleon.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/chameleon/test_modeling_chameleon.py b/tests/models/chameleon/test_modeling_chameleon.py index 9bcbdbf8a9..c393c9cf88 100644 --- a/tests/models/chameleon/test_modeling_chameleon.py +++ b/tests/models/chameleon/test_modeling_chameleon.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/chameleon/test_processor_chameleon.py b/tests/models/chameleon/test_processor_chameleon.py index 0bf2c2ddf2..2e0951dcf1 100644 --- a/tests/models/chameleon/test_processor_chameleon.py +++ b/tests/models/chameleon/test_processor_chameleon.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/chinese_clip/test_image_processing_chinese_clip.py b/tests/models/chinese_clip/test_image_processing_chinese_clip.py index 01bea098eb..bfacac7a16 100644 --- a/tests/models/chinese_clip/test_image_processing_chinese_clip.py +++ b/tests/models/chinese_clip/test_image_processing_chinese_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/chinese_clip/test_modeling_chinese_clip.py b/tests/models/chinese_clip/test_modeling_chinese_clip.py index 9593042883..9442be5462 100644 --- a/tests/models/chinese_clip/test_modeling_chinese_clip.py +++ b/tests/models/chinese_clip/test_modeling_chinese_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clap/test_feature_extraction_clap.py b/tests/models/clap/test_feature_extraction_clap.py index d0e2bb44a3..b2ccb50171 100644 --- a/tests/models/clap/test_feature_extraction_clap.py +++ b/tests/models/clap/test_feature_extraction_clap.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clap/test_modeling_clap.py b/tests/models/clap/test_modeling_clap.py index 21281ced3e..e828a54827 100644 --- a/tests/models/clap/test_modeling_clap.py +++ b/tests/models/clap/test_modeling_clap.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clip/test_image_processing_clip.py b/tests/models/clip/test_image_processing_clip.py index 7387ede6ed..86f53a7489 100644 --- a/tests/models/clip/test_image_processing_clip.py +++ b/tests/models/clip/test_image_processing_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clip/test_modeling_clip.py b/tests/models/clip/test_modeling_clip.py index 5600e67a70..df5cc14fc4 100644 --- a/tests/models/clip/test_modeling_clip.py +++ b/tests/models/clip/test_modeling_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,7 @@ import inspect import os import tempfile import unittest -from typing import Optional, Tuple +from typing import Optional import numpy as np import requests @@ -229,8 +228,8 @@ class CLIPModelTesterMixin(ModelTesterMixin): def test_eager_matches_sdpa_inference( self, torch_dtype: str, - use_attention_mask_options: Tuple[Optional[str], ...] = (None, "left", "right"), - logit_keys: Tuple[str, ...] = ("logits_per_image", "logits_per_text", "image_embeds", "text_embeds"), + use_attention_mask_options: tuple[Optional[str], ...] = (None, "left", "right"), + logit_keys: tuple[str, ...] = ("logits_per_image", "logits_per_text", "image_embeds", "text_embeds"), ): if not self.all_model_classes[0]._supports_sdpa: self.skipTest(f"{self.all_model_classes[0].__name__} does not support SDPA") diff --git a/tests/models/clip/test_modeling_tf_clip.py b/tests/models/clip/test_modeling_tf_clip.py index 83080db94b..27db72e397 100644 --- a/tests/models/clip/test_modeling_tf_clip.py +++ b/tests/models/clip/test_modeling_tf_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clip/test_tokenization_clip.py b/tests/models/clip/test_tokenization_clip.py index f0dfec6bd7..fca53f07cd 100644 --- a/tests/models/clip/test_tokenization_clip.py +++ b/tests/models/clip/test_tokenization_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clipseg/test_modeling_clipseg.py b/tests/models/clipseg/test_modeling_clipseg.py index 8511549926..0a0bc5a758 100644 --- a/tests/models/clipseg/test_modeling_clipseg.py +++ b/tests/models/clipseg/test_modeling_clipseg.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clvp/test_feature_extraction_clvp.py b/tests/models/clvp/test_feature_extraction_clvp.py index a536260f7a..78bf38e2df 100644 --- a/tests/models/clvp/test_feature_extraction_clvp.py +++ b/tests/models/clvp/test_feature_extraction_clvp.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clvp/test_modeling_clvp.py b/tests/models/clvp/test_modeling_clvp.py index 8064d4059e..60c165fbbe 100644 --- a/tests/models/clvp/test_modeling_clvp.py +++ b/tests/models/clvp/test_modeling_clvp.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/clvp/test_tokenization_clvp.py b/tests/models/clvp/test_tokenization_clvp.py index 1c526e84d1..eb7304d66f 100644 --- a/tests/models/clvp/test_tokenization_clvp.py +++ b/tests/models/clvp/test_tokenization_clvp.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ import json import os import unittest from functools import lru_cache -from typing import List from transformers import ClvpTokenizer @@ -90,7 +88,7 @@ class ClvpTokenizationTest(TokenizerTesterMixin, unittest.TestCase): # Copied from transformers.tests.models.layoutxlm.test_tokenization_layoutxlm.LayoutXLMTokenizationTest.test_add_special_tokens def test_add_special_tokens(self): - tokenizers: List[ClvpTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[ClvpTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): special_token = "[SPECIAL_TOKEN]" diff --git a/tests/models/code_llama/test_tokenization_code_llama.py b/tests/models/code_llama/test_tokenization_code_llama.py index 774c17f513..a12d2fc4c5 100644 --- a/tests/models/code_llama/test_tokenization_code_llama.py +++ b/tests/models/code_llama/test_tokenization_code_llama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -381,14 +380,14 @@ class LlamaIntegrationTest(unittest.TestCase): with tempfile.TemporaryDirectory() as dirname: self.rust_tokenizer.save_pretrained(dirname) - with open(os.path.join(dirname, "tokenizer.json"), "r") as f: + with open(os.path.join(dirname, "tokenizer.json")) as f: old_serialized = f.read() new_tokenizer = convert_slow_tokenizer(self.tokenizer) with tempfile.NamedTemporaryFile() as f: new_tokenizer.save(f.name) # Re-opening since `f` is in bytes. - new_serialized = open(f.name, "r").read() + new_serialized = open(f.name).read() with open("out_tokenizer.json", "w") as g: g.write(new_serialized) diff --git a/tests/models/codegen/test_modeling_codegen.py b/tests/models/codegen/test_modeling_codegen.py index 2cc2f74dd7..78f766a52a 100644 --- a/tests/models/codegen/test_modeling_codegen.py +++ b/tests/models/codegen/test_modeling_codegen.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/codegen/test_tokenization_codegen.py b/tests/models/codegen/test_tokenization_codegen.py index 28d388202b..a0ea547566 100644 --- a/tests/models/codegen/test_tokenization_codegen.py +++ b/tests/models/codegen/test_tokenization_codegen.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/cohere/test_modeling_cohere.py b/tests/models/cohere/test_modeling_cohere.py index 24adee07df..bebafedc7d 100644 --- a/tests/models/cohere/test_modeling_cohere.py +++ b/tests/models/cohere/test_modeling_cohere.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/cohere/test_tokenization_cohere.py b/tests/models/cohere/test_tokenization_cohere.py index cec1334a33..d162b99981 100644 --- a/tests/models/cohere/test_tokenization_cohere.py +++ b/tests/models/cohere/test_tokenization_cohere.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/cohere2/test_modeling_cohere2.py b/tests/models/cohere2/test_modeling_cohere2.py index 789649b832..63c067df57 100644 --- a/tests/models/cohere2/test_modeling_cohere2.py +++ b/tests/models/cohere2/test_modeling_cohere2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/colpali/test_modeling_colpali.py b/tests/models/colpali/test_modeling_colpali.py index 70ff0ed8bd..c0bcc91771 100644 --- a/tests/models/colpali/test_modeling_colpali.py +++ b/tests/models/colpali/test_modeling_colpali.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/conditional_detr/test_image_processing_conditional_detr.py b/tests/models/conditional_detr/test_image_processing_conditional_detr.py index 4f15b5e77b..46b7c15450 100644 --- a/tests/models/conditional_detr/test_image_processing_conditional_detr.py +++ b/tests/models/conditional_detr/test_image_processing_conditional_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -165,7 +164,7 @@ class ConditionalDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcess def test_call_pytorch_with_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -209,7 +208,7 @@ class ConditionalDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcess def test_call_pytorch_with_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -260,7 +259,7 @@ class ConditionalDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcess image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) annotations_0 = {"image_id": 39769, "annotations": target} @@ -380,7 +379,7 @@ class ConditionalDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcess image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) annotation_0 = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} diff --git a/tests/models/conditional_detr/test_modeling_conditional_detr.py b/tests/models/conditional_detr/test_modeling_conditional_detr.py index 118552fce5..c13079c5fd 100644 --- a/tests/models/conditional_detr/test_modeling_conditional_detr.py +++ b/tests/models/conditional_detr/test_modeling_conditional_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/convbert/test_modeling_convbert.py b/tests/models/convbert/test_modeling_convbert.py index 51daf2509c..8aba631c30 100644 --- a/tests/models/convbert/test_modeling_convbert.py +++ b/tests/models/convbert/test_modeling_convbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/convbert/test_modeling_tf_convbert.py b/tests/models/convbert/test_modeling_tf_convbert.py index a4e458e7d2..7bd21778eb 100644 --- a/tests/models/convbert/test_modeling_tf_convbert.py +++ b/tests/models/convbert/test_modeling_tf_convbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/convnext/test_image_processing_convnext.py b/tests/models/convnext/test_image_processing_convnext.py index 661f052efb..373eb16fce 100644 --- a/tests/models/convnext/test_image_processing_convnext.py +++ b/tests/models/convnext/test_image_processing_convnext.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022s HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/convnext/test_modeling_convnext.py b/tests/models/convnext/test_modeling_convnext.py index 694d3931a9..fce8f4a35b 100644 --- a/tests/models/convnext/test_modeling_convnext.py +++ b/tests/models/convnext/test_modeling_convnext.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/convnext/test_modeling_tf_convnext.py b/tests/models/convnext/test_modeling_tf_convnext.py index ec8ea8e13d..1e46e57fb2 100644 --- a/tests/models/convnext/test_modeling_tf_convnext.py +++ b/tests/models/convnext/test_modeling_tf_convnext.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ from __future__ import annotations import inspect import unittest -from typing import List, Tuple from transformers import ConvNextConfig from transformers.testing_utils import require_tf, require_vision, slow @@ -224,7 +222,7 @@ class TFConvNextModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.Test dict_output = model(dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: diff --git a/tests/models/convnextv2/test_modeling_convnextv2.py b/tests/models/convnextv2/test_modeling_convnextv2.py index 341f738fdd..f24b33c439 100644 --- a/tests/models/convnextv2/test_modeling_convnextv2.py +++ b/tests/models/convnextv2/test_modeling_convnextv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/convnextv2/test_modeling_tf_convnextv2.py b/tests/models/convnextv2/test_modeling_tf_convnextv2.py index 58b4795afd..08e458609c 100644 --- a/tests/models/convnextv2/test_modeling_tf_convnextv2.py +++ b/tests/models/convnextv2/test_modeling_tf_convnextv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ from __future__ import annotations import inspect import unittest -from typing import List, Tuple import numpy as np @@ -226,7 +224,7 @@ class TFConvNextV2ModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.Te dict_output = model(dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: diff --git a/tests/models/cpm/test_tokenization_cpm.py b/tests/models/cpm/test_tokenization_cpm.py index 870a932cb3..2719e01b32 100644 --- a/tests/models/cpm/test_tokenization_cpm.py +++ b/tests/models/cpm/test_tokenization_cpm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 HuggingFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/cpmant/test_modeling_cpmant.py b/tests/models/cpmant/test_modeling_cpmant.py index 4a6c28e1eb..bf3a655c8d 100644 --- a/tests/models/cpmant/test_modeling_cpmant.py +++ b/tests/models/cpmant/test_modeling_cpmant.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The OpenBMB Team and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/cpmant/test_tokenization_cpmant.py b/tests/models/cpmant/test_tokenization_cpmant.py index 32449763ea..c7c3209f2d 100644 --- a/tests/models/cpmant/test_tokenization_cpmant.py +++ b/tests/models/cpmant/test_tokenization_cpmant.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The OpenBMB Team and The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/ctrl/test_modeling_ctrl.py b/tests/models/ctrl/test_modeling_ctrl.py index 1e3a40f833..860693b5cc 100644 --- a/tests/models/ctrl/test_modeling_ctrl.py +++ b/tests/models/ctrl/test_modeling_ctrl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Salesforce and HuggingFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/ctrl/test_modeling_tf_ctrl.py b/tests/models/ctrl/test_modeling_tf_ctrl.py index 8a08fe0798..38623d442a 100644 --- a/tests/models/ctrl/test_modeling_tf_ctrl.py +++ b/tests/models/ctrl/test_modeling_tf_ctrl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/ctrl/test_tokenization_ctrl.py b/tests/models/ctrl/test_tokenization_ctrl.py index e22ca8abe5..f62e49708c 100644 --- a/tests/models/ctrl/test_tokenization_ctrl.py +++ b/tests/models/ctrl/test_tokenization_ctrl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Salesforce and HuggingFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/cvt/test_modeling_cvt.py b/tests/models/cvt/test_modeling_cvt.py index a63789d887..cb7007bb6b 100644 --- a/tests/models/cvt/test_modeling_cvt.py +++ b/tests/models/cvt/test_modeling_cvt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dab_detr/test_modeling_dab_detr.py b/tests/models/dab_detr/test_modeling_dab_detr.py index 572efc5de5..e040a2c662 100644 --- a/tests/models/dab_detr/test_modeling_dab_detr.py +++ b/tests/models/dab_detr/test_modeling_dab_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,6 @@ import inspect import math import unittest -from typing import Dict, List, Tuple from transformers import DabDetrConfig, ResNetConfig, is_torch_available, is_vision_available from transformers.testing_utils import require_timm, require_torch, require_vision, slow, torch_device @@ -277,10 +275,10 @@ class DabDetrModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase) dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/dac/test_feature_extraction_dac.py b/tests/models/dac/test_feature_extraction_dac.py index 1bc5439046..13d7232607 100644 --- a/tests/models/dac/test_feature_extraction_dac.py +++ b/tests/models/dac/test_feature_extraction_dac.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dac/test_modeling_dac.py b/tests/models/dac/test_modeling_dac.py index 729e40463e..d001a953ce 100644 --- a/tests/models/dac/test_modeling_dac.py +++ b/tests/models/dac/test_modeling_dac.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ import inspect import os import tempfile import unittest -from typing import Dict, List, Tuple import numpy as np from datasets import Audio, load_dataset @@ -333,10 +331,10 @@ class DacModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): @@ -418,7 +416,7 @@ class DacIntegrationTest(unittest.TestCase): model_name = "dac_16khz" - model_id = "descript/{}".format(model_name) + model_id = f"descript/{model_name}" model = DacModel.from_pretrained(model_id, force_download=True).to(torch_device).eval() processor = AutoProcessor.from_pretrained(model_id) @@ -471,7 +469,7 @@ class DacIntegrationTest(unittest.TestCase): model_name = "dac_24khz" - model_id = "descript/{}".format(model_name) + model_id = f"descript/{model_name}" model = DacModel.from_pretrained(model_id, force_download=True).to(torch_device).eval() processor = AutoProcessor.from_pretrained(model_id) @@ -545,7 +543,7 @@ class DacIntegrationTest(unittest.TestCase): model_name = "dac_44khz" - model_id = "descript/{}".format(model_name) + model_id = f"descript/{model_name}" model = DacModel.from_pretrained(model_id).to(torch_device).eval() processor = AutoProcessor.from_pretrained(model_id) @@ -600,7 +598,7 @@ class DacIntegrationTest(unittest.TestCase): model_name = "dac_16khz" - model_id = "descript/{}".format(model_name) + model_id = f"descript/{model_name}" model = DacModel.from_pretrained(model_id).to(torch_device) processor = AutoProcessor.from_pretrained(model_id) @@ -657,7 +655,7 @@ class DacIntegrationTest(unittest.TestCase): model_name = "dac_24khz" - model_id = "descript/{}".format(model_name) + model_id = f"descript/{model_name}" model = DacModel.from_pretrained(model_id).to(torch_device) processor = AutoProcessor.from_pretrained(model_id) @@ -714,7 +712,7 @@ class DacIntegrationTest(unittest.TestCase): model_name = "dac_44khz" - model_id = "descript/{}".format(model_name) + model_id = f"descript/{model_name}" model = DacModel.from_pretrained(model_id).to(torch_device) processor = AutoProcessor.from_pretrained(model_id) diff --git a/tests/models/data2vec/test_modeling_data2vec_audio.py b/tests/models/data2vec/test_modeling_data2vec_audio.py index 7aec53a6e7..96e970beb6 100644 --- a/tests/models/data2vec/test_modeling_data2vec_audio.py +++ b/tests/models/data2vec/test_modeling_data2vec_audio.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/data2vec/test_modeling_data2vec_text.py b/tests/models/data2vec/test_modeling_data2vec_text.py index 7bc2d4eb94..fa9a53fb81 100644 --- a/tests/models/data2vec/test_modeling_data2vec_text.py +++ b/tests/models/data2vec/test_modeling_data2vec_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/data2vec/test_modeling_data2vec_vision.py b/tests/models/data2vec/test_modeling_data2vec_vision.py index ee0511a055..69c48b0708 100644 --- a/tests/models/data2vec/test_modeling_data2vec_vision.py +++ b/tests/models/data2vec/test_modeling_data2vec_vision.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/data2vec/test_modeling_tf_data2vec_vision.py b/tests/models/data2vec/test_modeling_tf_data2vec_vision.py index 5c7ff88355..3f88801534 100644 --- a/tests/models/data2vec/test_modeling_tf_data2vec_vision.py +++ b/tests/models/data2vec/test_modeling_tf_data2vec_vision.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -168,7 +167,7 @@ class TFData2VecVisionModelTester: def prepare_config_and_inputs_for_keras_fit(self): config_and_inputs = self.prepare_config_and_inputs() config, pixel_values, _, _ = config_and_inputs - inputs_dict = {"pixel_values": pixel_values, "labels": tf.zeros((self.batch_size))} + inputs_dict = {"pixel_values": pixel_values, "labels": tf.zeros(self.batch_size)} return config, inputs_dict diff --git a/tests/models/dbrx/test_modeling_dbrx.py b/tests/models/dbrx/test_modeling_dbrx.py index dbe0cb8b27..512bd6a02c 100644 --- a/tests/models/dbrx/test_modeling_dbrx.py +++ b/tests/models/dbrx/test_modeling_dbrx.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deberta/test_modeling_deberta.py b/tests/models/deberta/test_modeling_deberta.py index d6c15efa4a..8ec4eefc4f 100644 --- a/tests/models/deberta/test_modeling_deberta.py +++ b/tests/models/deberta/test_modeling_deberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Microsoft Authors and the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deberta/test_modeling_tf_deberta.py b/tests/models/deberta/test_modeling_tf_deberta.py index 14a99ea947..ea1e716dd6 100644 --- a/tests/models/deberta/test_modeling_tf_deberta.py +++ b/tests/models/deberta/test_modeling_tf_deberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deberta/test_tokenization_deberta.py b/tests/models/deberta/test_tokenization_deberta.py index dc3c84c871..ad625eabf0 100644 --- a/tests/models/deberta/test_tokenization_deberta.py +++ b/tests/models/deberta/test_tokenization_deberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 Hugging Face inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deberta_v2/test_modeling_deberta_v2.py b/tests/models/deberta_v2/test_modeling_deberta_v2.py index af2dfe03b3..6de08d3f4b 100644 --- a/tests/models/deberta_v2/test_modeling_deberta_v2.py +++ b/tests/models/deberta_v2/test_modeling_deberta_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Microsoft Authors and the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py b/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py index b46f68525d..b69e2eb489 100644 --- a/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py +++ b/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deberta_v2/test_tokenization_deberta_v2.py b/tests/models/deberta_v2/test_tokenization_deberta_v2.py index c2e57a5809..e629f27924 100644 --- a/tests/models/deberta_v2/test_tokenization_deberta_v2.py +++ b/tests/models/deberta_v2/test_tokenization_deberta_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 Hugging Face inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/decision_transformer/test_modeling_decision_transformer.py b/tests/models/decision_transformer/test_modeling_decision_transformer.py index e004629c9c..b6bdeaa083 100644 --- a/tests/models/decision_transformer/test_modeling_decision_transformer.py +++ b/tests/models/decision_transformer/test_modeling_decision_transformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deepseek_v3/test_modeling_deepseek_v3.py b/tests/models/deepseek_v3/test_modeling_deepseek_v3.py index f6394fe354..5e5737df5a 100644 --- a/tests/models/deepseek_v3/test_modeling_deepseek_v3.py +++ b/tests/models/deepseek_v3/test_modeling_deepseek_v3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deformable_detr/test_image_processing_deformable_detr.py b/tests/models/deformable_detr/test_image_processing_deformable_detr.py index 25aa486b54..f0fb0db022 100644 --- a/tests/models/deformable_detr/test_image_processing_deformable_detr.py +++ b/tests/models/deformable_detr/test_image_processing_deformable_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -170,7 +169,7 @@ class DeformableDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessi def test_call_pytorch_with_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -215,7 +214,7 @@ class DeformableDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessi def test_call_pytorch_with_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -268,7 +267,7 @@ class DeformableDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessi image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) annotations_0 = {"image_id": 39769, "annotations": target} @@ -388,7 +387,7 @@ class DeformableDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessi image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) annotation_0 = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -613,7 +612,7 @@ class DeformableDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessi def test_fast_processor_equivalence_cpu_gpu_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -671,7 +670,7 @@ class DeformableDetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessi def test_fast_processor_equivalence_cpu_gpu_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} diff --git a/tests/models/deformable_detr/test_modeling_deformable_detr.py b/tests/models/deformable_detr/test_modeling_deformable_detr.py index e3441e606d..6274a7e1ef 100644 --- a/tests/models/deformable_detr/test_modeling_deformable_detr.py +++ b/tests/models/deformable_detr/test_modeling_deformable_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,6 @@ import inspect import math import unittest -from typing import Dict, List, Tuple from transformers import DeformableDetrConfig, ResNetConfig, is_torch_available, is_vision_available from transformers.file_utils import cached_property @@ -384,10 +382,10 @@ class DeformableDetrModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.Te dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/deit/test_image_processing_deit.py b/tests/models/deit/test_image_processing_deit.py index d3e96d439c..9bc204f41a 100644 --- a/tests/models/deit/test_image_processing_deit.py +++ b/tests/models/deit/test_image_processing_deit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deit/test_modeling_deit.py b/tests/models/deit/test_modeling_deit.py index 333ed0fa95..50ccdbfb5f 100644 --- a/tests/models/deit/test_modeling_deit.py +++ b/tests/models/deit/test_modeling_deit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/deit/test_modeling_tf_deit.py b/tests/models/deit/test_modeling_tf_deit.py index 537d975179..1ca091f526 100644 --- a/tests/models/deit/test_modeling_tf_deit.py +++ b/tests/models/deit/test_modeling_tf_deit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/depth_anything/test_modeling_depth_anything.py b/tests/models/depth_anything/test_modeling_depth_anything.py index b9d259b1c7..bf9bc907dc 100644 --- a/tests/models/depth_anything/test_modeling_depth_anything.py +++ b/tests/models/depth_anything/test_modeling_depth_anything.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/depth_pro/test_image_processing_depth_pro.py b/tests/models/depth_pro/test_image_processing_depth_pro.py index b30931a86c..a14b606171 100644 --- a/tests/models/depth_pro/test_image_processing_depth_pro.py +++ b/tests/models/depth_pro/test_image_processing_depth_pro.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/depth_pro/test_modeling_depth_pro.py b/tests/models/depth_pro/test_modeling_depth_pro.py index cb38380dc7..bd35887e58 100644 --- a/tests/models/depth_pro/test_modeling_depth_pro.py +++ b/tests/models/depth_pro/test_modeling_depth_pro.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/detr/test_image_processing_detr.py b/tests/models/detr/test_image_processing_detr.py index 6f19de09dc..deba250ae1 100644 --- a/tests/models/detr/test_image_processing_detr.py +++ b/tests/models/detr/test_image_processing_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -172,7 +171,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi def test_should_raise_if_annotation_format_invalid(self): image_processor_dict = self.image_processor_tester.prepare_image_processor_dict() - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: detection_target = json.loads(f.read()) annotations = {"image_id": 39769, "annotations": detection_target} @@ -195,7 +194,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi def test_valid_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) params = {"image_id": 39769, "annotations": target} @@ -232,7 +231,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi def test_call_pytorch_with_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -277,7 +276,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi def test_call_pytorch_with_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -329,7 +328,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) annotations_0 = {"image_id": 39769, "annotations": target} @@ -448,7 +447,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) annotation_0 = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -672,7 +671,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi def test_fast_processor_equivalence_cpu_gpu_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -728,7 +727,7 @@ class DetrImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMixi def test_fast_processor_equivalence_cpu_gpu_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} diff --git a/tests/models/detr/test_modeling_detr.py b/tests/models/detr/test_modeling_detr.py index 003deceab7..6d31cdc65d 100644 --- a/tests/models/detr/test_modeling_detr.py +++ b/tests/models/detr/test_modeling_detr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/diffllama/test_modeling_diffllama.py b/tests/models/diffllama/test_modeling_diffllama.py index f56b0f764b..c738fbf76d 100644 --- a/tests/models/diffllama/test_modeling_diffllama.py +++ b/tests/models/diffllama/test_modeling_diffllama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dinat/test_modeling_dinat.py b/tests/models/dinat/test_modeling_dinat.py index 7c49827051..1de68988e7 100644 --- a/tests/models/dinat/test_modeling_dinat.py +++ b/tests/models/dinat/test_modeling_dinat.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dinov2/test_modeling_dinov2.py b/tests/models/dinov2/test_modeling_dinov2.py index a8f11c9172..49a70380d3 100644 --- a/tests/models/dinov2/test_modeling_dinov2.py +++ b/tests/models/dinov2/test_modeling_dinov2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dinov2/test_modeling_flax_dinov2.py b/tests/models/dinov2/test_modeling_flax_dinov2.py index 09ce20611a..161e49e3db 100644 --- a/tests/models/dinov2/test_modeling_flax_dinov2.py +++ b/tests/models/dinov2/test_modeling_flax_dinov2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dinov2_with_registers/test_modeling_dinov2_with_registers.py b/tests/models/dinov2_with_registers/test_modeling_dinov2_with_registers.py index c40af0c197..74ab8d545f 100644 --- a/tests/models/dinov2_with_registers/test_modeling_dinov2_with_registers.py +++ b/tests/models/dinov2_with_registers/test_modeling_dinov2_with_registers.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/distilbert/test_modeling_distilbert.py b/tests/models/distilbert/test_modeling_distilbert.py index 367785b5e2..32f4ea349b 100644 --- a/tests/models/distilbert/test_modeling_distilbert.py +++ b/tests/models/distilbert/test_modeling_distilbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/distilbert/test_modeling_tf_distilbert.py b/tests/models/distilbert/test_modeling_tf_distilbert.py index 270cea00de..674acdad26 100644 --- a/tests/models/distilbert/test_modeling_tf_distilbert.py +++ b/tests/models/distilbert/test_modeling_tf_distilbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/distilbert/test_tokenization_distilbert.py b/tests/models/distilbert/test_tokenization_distilbert.py index 42f6d6a4ad..cf92b48a3d 100644 --- a/tests/models/distilbert/test_tokenization_distilbert.py +++ b/tests/models/distilbert/test_tokenization_distilbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dit/test_modeling_dit.py b/tests/models/dit/test_modeling_dit.py index d0f9f79b32..1e29cc0fdc 100644 --- a/tests/models/dit/test_modeling_dit.py +++ b/tests/models/dit/test_modeling_dit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/donut/test_image_processing_donut.py b/tests/models/donut/test_image_processing_donut.py index 052894c0cb..07da7fe74d 100644 --- a/tests/models/donut/test_image_processing_donut.py +++ b/tests/models/donut/test_image_processing_donut.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/donut/test_modeling_donut_swin.py b/tests/models/donut/test_modeling_donut_swin.py index 11c01c39fa..cb7dc99302 100644 --- a/tests/models/donut/test_modeling_donut_swin.py +++ b/tests/models/donut/test_modeling_donut_swin.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/donut/test_processor_donut.py b/tests/models/donut/test_processor_donut.py index cf720e17b0..ddc63a0add 100644 --- a/tests/models/donut/test_processor_donut.py +++ b/tests/models/donut/test_processor_donut.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpr/test_modeling_dpr.py b/tests/models/dpr/test_modeling_dpr.py index 3f05bc242f..f7c4f6eb18 100644 --- a/tests/models/dpr/test_modeling_dpr.py +++ b/tests/models/dpr/test_modeling_dpr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Huggingface # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpr/test_modeling_tf_dpr.py b/tests/models/dpr/test_modeling_tf_dpr.py index 92d74e72e3..81427f3d94 100644 --- a/tests/models/dpr/test_modeling_tf_dpr.py +++ b/tests/models/dpr/test_modeling_tf_dpr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Huggingface # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpr/test_tokenization_dpr.py b/tests/models/dpr/test_tokenization_dpr.py index 28c5562ec8..ab1401b295 100644 --- a/tests/models/dpr/test_tokenization_dpr.py +++ b/tests/models/dpr/test_tokenization_dpr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Huggingface # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpt/test_image_processing_dpt.py b/tests/models/dpt/test_image_processing_dpt.py index feb551d3be..8d5e8ea75e 100644 --- a/tests/models/dpt/test_image_processing_dpt.py +++ b/tests/models/dpt/test_image_processing_dpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpt/test_modeling_dpt.py b/tests/models/dpt/test_modeling_dpt.py index bdfd480a90..248b40121a 100644 --- a/tests/models/dpt/test_modeling_dpt.py +++ b/tests/models/dpt/test_modeling_dpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpt/test_modeling_dpt_auto_backbone.py b/tests/models/dpt/test_modeling_dpt_auto_backbone.py index e4c40ca809..91863cc46e 100644 --- a/tests/models/dpt/test_modeling_dpt_auto_backbone.py +++ b/tests/models/dpt/test_modeling_dpt_auto_backbone.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/dpt/test_modeling_dpt_hybrid.py b/tests/models/dpt/test_modeling_dpt_hybrid.py index cf16620314..fbdd88278e 100644 --- a/tests/models/dpt/test_modeling_dpt_hybrid.py +++ b/tests/models/dpt/test_modeling_dpt_hybrid.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/efficientnet/test_image_processing_efficientnet.py b/tests/models/efficientnet/test_image_processing_efficientnet.py index 618885dc97..577798e9ae 100644 --- a/tests/models/efficientnet/test_image_processing_efficientnet.py +++ b/tests/models/efficientnet/test_image_processing_efficientnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/efficientnet/test_modeling_efficientnet.py b/tests/models/efficientnet/test_modeling_efficientnet.py index 68bc175ad4..f0706ad153 100644 --- a/tests/models/efficientnet/test_modeling_efficientnet.py +++ b/tests/models/efficientnet/test_modeling_efficientnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/electra/test_modeling_electra.py b/tests/models/electra/test_modeling_electra.py index 08865f22ab..7d451ff637 100644 --- a/tests/models/electra/test_modeling_electra.py +++ b/tests/models/electra/test_modeling_electra.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/electra/test_modeling_tf_electra.py b/tests/models/electra/test_modeling_tf_electra.py index aba6db1efa..2b7e8d1a18 100644 --- a/tests/models/electra/test_modeling_tf_electra.py +++ b/tests/models/electra/test_modeling_tf_electra.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/electra/test_tokenization_electra.py b/tests/models/electra/test_tokenization_electra.py index 0155c21bf2..4c736e1670 100644 --- a/tests/models/electra/test_tokenization_electra.py +++ b/tests/models/electra/test_tokenization_electra.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/emu3/test_modeling_emu3.py b/tests/models/emu3/test_modeling_emu3.py index 491fd9f9ec..8f71e8a42c 100644 --- a/tests/models/emu3/test_modeling_emu3.py +++ b/tests/models/emu3/test_modeling_emu3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/emu3/test_processor_emu3.py b/tests/models/emu3/test_processor_emu3.py index c7b792c2a3..bdecd62ec2 100644 --- a/tests/models/emu3/test_processor_emu3.py +++ b/tests/models/emu3/test_processor_emu3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/encodec/test_feature_extraction_encodec.py b/tests/models/encodec/test_feature_extraction_encodec.py index d809a90f12..3dc4c5fbb7 100644 --- a/tests/models/encodec/test_feature_extraction_encodec.py +++ b/tests/models/encodec/test_feature_extraction_encodec.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021-2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/encodec/test_modeling_encodec.py b/tests/models/encodec/test_modeling_encodec.py index f7e9d63915..bb6458bbc3 100644 --- a/tests/models/encodec/test_modeling_encodec.py +++ b/tests/models/encodec/test_modeling_encodec.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/encoder_decoder/test_modeling_encoder_decoder.py b/tests/models/encoder_decoder/test_modeling_encoder_decoder.py index 4f1cb32348..6d2286bae3 100644 --- a/tests/models/encoder_decoder/test_modeling_encoder_decoder.py +++ b/tests/models/encoder_decoder/test_modeling_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py b/tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py index 3629818200..b17f9ed37b 100644 --- a/tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py +++ b/tests/models/encoder_decoder/test_modeling_flax_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -311,7 +310,7 @@ class FlaxEncoderDecoderMixin: self.check_encoder_decoder_model_generate(**input_ids_dict) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") @slow diff --git a/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py b/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py index cd35578273..5e1da3242b 100644 --- a/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py +++ b/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -414,7 +413,7 @@ class TFEncoderDecoderMixin: self.check_encoder_decoder_model_generate(**input_ids_dict) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and tf is {diff} (>= {tol}).") def test_model_save_load_from_pretrained(self): diff --git a/tests/models/ernie/test_modeling_ernie.py b/tests/models/ernie/test_modeling_ernie.py index 33ebef8e7b..aec833a7f4 100644 --- a/tests/models/ernie/test_modeling_ernie.py +++ b/tests/models/ernie/test_modeling_ernie.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/esm/test_modeling_esm.py b/tests/models/esm/test_modeling_esm.py index 7be71c22c7..74f4c277d0 100644 --- a/tests/models/esm/test_modeling_esm.py +++ b/tests/models/esm/test_modeling_esm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/esm/test_modeling_esmfold.py b/tests/models/esm/test_modeling_esmfold.py index 03b1981dc8..b13e7fe58b 100644 --- a/tests/models/esm/test_modeling_esmfold.py +++ b/tests/models/esm/test_modeling_esmfold.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/esm/test_modeling_tf_esm.py b/tests/models/esm/test_modeling_tf_esm.py index 4accc16256..52d163d2dc 100644 --- a/tests/models/esm/test_modeling_tf_esm.py +++ b/tests/models/esm/test_modeling_tf_esm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/esm/test_tokenization_esm.py b/tests/models/esm/test_tokenization_esm.py index e0013d8a18..57c66d53a8 100644 --- a/tests/models/esm/test_tokenization_esm.py +++ b/tests/models/esm/test_tokenization_esm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ import os import tempfile import unittest from functools import lru_cache -from typing import List from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer from transformers.testing_utils import require_tokenizers @@ -37,12 +35,12 @@ class ESMTokenizationTest(unittest.TestCase): super().setUpClass() cls.tmpdirname = tempfile.mkdtemp() - vocab_tokens: List[str] = ["", "", "", "", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "", ""] # fmt: skip + vocab_tokens: list[str] = ["", "", "", "", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "", ""] # fmt: skip cls.vocab_file = os.path.join(cls.tmpdirname, VOCAB_FILES_NAMES["vocab_file"]) with open(cls.vocab_file, "w", encoding="utf-8") as vocab_writer: vocab_writer.write("".join([x + "\n" for x in vocab_tokens])) - def get_tokenizers(cls, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(cls, **kwargs) -> list[PreTrainedTokenizerBase]: return [cls.get_tokenizer(**kwargs)] @classmethod diff --git a/tests/models/falcon/test_modeling_falcon.py b/tests/models/falcon/test_modeling_falcon.py index a40b9fa26b..cf52de0036 100644 --- a/tests/models/falcon/test_modeling_falcon.py +++ b/tests/models/falcon/test_modeling_falcon.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/falcon_mamba/test_modeling_falcon_mamba.py b/tests/models/falcon_mamba/test_modeling_falcon_mamba.py index 4e372a5fd9..d724f70e19 100644 --- a/tests/models/falcon_mamba/test_modeling_falcon_mamba.py +++ b/tests/models/falcon_mamba/test_modeling_falcon_mamba.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ import math import unittest -from typing import Dict, List, Tuple from unittest.util import safe_repr from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, FalconMambaConfig, is_torch_available @@ -304,7 +302,7 @@ class FalconMambaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTest is_inside_interval = (min_value >= expected_min) and (max_value <= expected_max) if not is_inside_interval: - standardMsg = "%s not found in %s" % (safe_repr(member), safe_repr(container)) + standardMsg = f"{safe_repr(member)} not found in {safe_repr(container)}" self.fail(self._formatMessage(msg, standardMsg)) def test_config(self): @@ -399,10 +397,10 @@ class FalconMambaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTest if isinstance(tuple_object, MambaCache): # MODIFIED PART START recursive_check(tuple_object.conv_states, dict_object.conv_states) recursive_check(tuple_object.ssm_states, dict_object.ssm_states) - elif isinstance(tuple_object, (List, Tuple)): # MODIFIED PART END + elif isinstance(tuple_object, (list, tuple)): # MODIFIED PART END for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/fastspeech2_conformer/test_modeling_fastspeech2_conformer.py b/tests/models/fastspeech2_conformer/test_modeling_fastspeech2_conformer.py index 0480335f05..0e0562da92 100644 --- a/tests/models/fastspeech2_conformer/test_modeling_fastspeech2_conformer.py +++ b/tests/models/fastspeech2_conformer/test_modeling_fastspeech2_conformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/fastspeech2_conformer/test_tokenization_fastspeech2_conformer.py b/tests/models/fastspeech2_conformer/test_tokenization_fastspeech2_conformer.py index 23c8a35dc6..d42a774d7c 100644 --- a/tests/models/fastspeech2_conformer/test_tokenization_fastspeech2_conformer.py +++ b/tests/models/fastspeech2_conformer/test_tokenization_fastspeech2_conformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/flaubert/test_modeling_flaubert.py b/tests/models/flaubert/test_modeling_flaubert.py index 4211e92e21..f98773a119 100644 --- a/tests/models/flaubert/test_modeling_flaubert.py +++ b/tests/models/flaubert/test_modeling_flaubert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/flaubert/test_modeling_tf_flaubert.py b/tests/models/flaubert/test_modeling_tf_flaubert.py index 40b9c1c171..1a2931c398 100644 --- a/tests/models/flaubert/test_modeling_tf_flaubert.py +++ b/tests/models/flaubert/test_modeling_tf_flaubert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/flaubert/test_tokenization_flaubert.py b/tests/models/flaubert/test_tokenization_flaubert.py index 0fd42da306..30c6534988 100644 --- a/tests/models/flaubert/test_tokenization_flaubert.py +++ b/tests/models/flaubert/test_tokenization_flaubert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/flava/test_image_processing_flava.py b/tests/models/flava/test_image_processing_flava.py index e3c1f5b5b5..b7371c8f9b 100644 --- a/tests/models/flava/test_image_processing_flava.py +++ b/tests/models/flava/test_image_processing_flava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Meta Platforms authors and HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/flava/test_modeling_flava.py b/tests/models/flava/test_modeling_flava.py index 3e3321a314..acdac4dd87 100644 --- a/tests/models/flava/test_modeling_flava.py +++ b/tests/models/flava/test_modeling_flava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Meta Platforms authors and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/fnet/test_modeling_fnet.py b/tests/models/fnet/test_modeling_fnet.py index eab0f2598e..eca30656dd 100644 --- a/tests/models/fnet/test_modeling_fnet.py +++ b/tests/models/fnet/test_modeling_fnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ """Testing suite for the PyTorch FNet model.""" import unittest -from typing import Dict, List, Tuple from transformers import FNetConfig, is_torch_available from transformers.models.auto import get_values @@ -325,10 +323,10 @@ class FNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/fnet/test_tokenization_fnet.py b/tests/models/fnet/test_tokenization_fnet.py index c8156a7b20..b70aa33e0a 100644 --- a/tests/models/fnet/test_tokenization_fnet.py +++ b/tests/models/fnet/test_tokenization_fnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 Hugging Face inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/focalnet/test_modeling_focalnet.py b/tests/models/focalnet/test_modeling_focalnet.py index 2960234c3b..d272f25891 100644 --- a/tests/models/focalnet/test_modeling_focalnet.py +++ b/tests/models/focalnet/test_modeling_focalnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/fsmt/test_modeling_fsmt.py b/tests/models/fsmt/test_modeling_fsmt.py index 4119769676..e10a5fbae9 100644 --- a/tests/models/fsmt/test_modeling_fsmt.py +++ b/tests/models/fsmt/test_modeling_fsmt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Huggingface # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -409,7 +408,7 @@ class FSMTHeadTests(unittest.TestCase): def test_prepare_fsmt_decoder_inputs(self): config, *_ = self._get_config_and_data() - input_ids = _long_tensor(([4, 4, 2])) + input_ids = _long_tensor([4, 4, 2]) decoder_input_ids = _long_tensor([[26388, 2, config.pad_token_id]]) causal_mask_dtype = torch.float32 ignore = torch.finfo(causal_mask_dtype).min diff --git a/tests/models/fsmt/test_tokenization_fsmt.py b/tests/models/fsmt/test_tokenization_fsmt.py index cbc9692255..bfaf3df195 100644 --- a/tests/models/fsmt/test_tokenization_fsmt.py +++ b/tests/models/fsmt/test_tokenization_fsmt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/funnel/test_modeling_funnel.py b/tests/models/funnel/test_modeling_funnel.py index 6bd0826861..3d28924bee 100644 --- a/tests/models/funnel/test_modeling_funnel.py +++ b/tests/models/funnel/test_modeling_funnel.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/funnel/test_modeling_tf_funnel.py b/tests/models/funnel/test_modeling_tf_funnel.py index b8327c86ac..673982eb7b 100644 --- a/tests/models/funnel/test_modeling_tf_funnel.py +++ b/tests/models/funnel/test_modeling_tf_funnel.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/funnel/test_tokenization_funnel.py b/tests/models/funnel/test_tokenization_funnel.py index d5e22a3c6e..2d04fc0ac2 100644 --- a/tests/models/funnel/test_tokenization_funnel.py +++ b/tests/models/funnel/test_tokenization_funnel.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/fuyu/test_modeling_fuyu.py b/tests/models/fuyu/test_modeling_fuyu.py index 513486766c..06f0171e46 100644 --- a/tests/models/fuyu/test_modeling_fuyu.py +++ b/tests/models/fuyu/test_modeling_fuyu.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gemma/test_modeling_flax_gemma.py b/tests/models/gemma/test_modeling_flax_gemma.py index e8582268fe..8bd5a5bb41 100644 --- a/tests/models/gemma/test_modeling_flax_gemma.py +++ b/tests/models/gemma/test_modeling_flax_gemma.py @@ -135,7 +135,7 @@ class FlaxGemmaModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, input_ids, attention_mask): @@ -168,7 +168,7 @@ class FlaxGemmaModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/gemma/test_modeling_gemma.py b/tests/models/gemma/test_modeling_gemma.py index 9cea971a97..5e45e78a44 100644 --- a/tests/models/gemma/test_modeling_gemma.py +++ b/tests/models/gemma/test_modeling_gemma.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gemma/test_tokenization_gemma.py b/tests/models/gemma/test_tokenization_gemma.py index e48d19a253..b56a8e9591 100644 --- a/tests/models/gemma/test_tokenization_gemma.py +++ b/tests/models/gemma/test_tokenization_gemma.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -242,14 +241,14 @@ class GemmaIntegrationTest(unittest.TestCase): with tempfile.TemporaryDirectory() as dirname: self.rust_tokenizer.save_pretrained(dirname) - with open(os.path.join(dirname, "tokenizer.json"), "r") as f: + with open(os.path.join(dirname, "tokenizer.json")) as f: old_serialized = f.read() new_tokenizer = convert_slow_tokenizer(self.tokenizer) with tempfile.NamedTemporaryFile() as f: new_tokenizer.save(f.name) # Re-opening since `f` is in bytes. - new_serialized = open(f.name, "r").read() + new_serialized = open(f.name).read() with open("out_tokenizer.json", "w") as g: g.write(new_serialized) diff --git a/tests/models/gemma2/test_modeling_gemma2.py b/tests/models/gemma2/test_modeling_gemma2.py index cf27d90a9b..3d396d8f7f 100644 --- a/tests/models/gemma2/test_modeling_gemma2.py +++ b/tests/models/gemma2/test_modeling_gemma2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gemma3/test_image_processing_gemma3.py b/tests/models/gemma3/test_image_processing_gemma3.py index 28410f2d51..a32e475da0 100644 --- a/tests/models/gemma3/test_image_processing_gemma3.py +++ b/tests/models/gemma3/test_image_processing_gemma3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gemma3/test_modeling_gemma3.py b/tests/models/gemma3/test_modeling_gemma3.py index 7aba3454bd..935d8b884a 100644 --- a/tests/models/gemma3/test_modeling_gemma3.py +++ b/tests/models/gemma3/test_modeling_gemma3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/git/test_modeling_git.py b/tests/models/git/test_modeling_git.py index 03f7c8285b..38aa2b4e87 100644 --- a/tests/models/git/test_modeling_git.py +++ b/tests/models/git/test_modeling_git.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/glm/test_modeling_glm.py b/tests/models/glm/test_modeling_glm.py index ce9ed841b4..852f9524eb 100644 --- a/tests/models/glm/test_modeling_glm.py +++ b/tests/models/glm/test_modeling_glm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/glpn/test_image_processing_glpn.py b/tests/models/glpn/test_image_processing_glpn.py index 43d5da0707..7f6a960755 100644 --- a/tests/models/glpn/test_image_processing_glpn.py +++ b/tests/models/glpn/test_image_processing_glpn.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/glpn/test_modeling_glpn.py b/tests/models/glpn/test_modeling_glpn.py index c4dd380a0d..94f357455b 100644 --- a/tests/models/glpn/test_modeling_glpn.py +++ b/tests/models/glpn/test_modeling_glpn.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/got_ocr2/test_image_processing_got_ocr2.py b/tests/models/got_ocr2/test_image_processing_got_ocr2.py index 93cd347dea..a47dccf063 100644 --- a/tests/models/got_ocr2/test_image_processing_got_ocr2.py +++ b/tests/models/got_ocr2/test_image_processing_got_ocr2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/got_ocr2/test_modeling_got_ocr2.py b/tests/models/got_ocr2/test_modeling_got_ocr2.py index 29c69dc586..f9ea723fd9 100644 --- a/tests/models/got_ocr2/test_modeling_got_ocr2.py +++ b/tests/models/got_ocr2/test_modeling_got_ocr2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt2/test_modeling_flax_gpt2.py b/tests/models/gpt2/test_modeling_flax_gpt2.py index 5beb43d90e..3297a3c45d 100644 --- a/tests/models/gpt2/test_modeling_flax_gpt2.py +++ b/tests/models/gpt2/test_modeling_flax_gpt2.py @@ -141,7 +141,7 @@ class FlaxGPT2ModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, input_ids, attention_mask): @@ -174,7 +174,7 @@ class FlaxGPT2ModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_bool_attention_mask_in_generation(self, model_class_name, config, input_ids, attention_mask): diff --git a/tests/models/gpt2/test_modeling_gpt2.py b/tests/models/gpt2/test_modeling_gpt2.py index 603d8d88a7..44e342539b 100644 --- a/tests/models/gpt2/test_modeling_gpt2.py +++ b/tests/models/gpt2/test_modeling_gpt2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt2/test_modeling_tf_gpt2.py b/tests/models/gpt2/test_modeling_tf_gpt2.py index ed4c4a2e89..76ecd6d15b 100644 --- a/tests/models/gpt2/test_modeling_tf_gpt2.py +++ b/tests/models/gpt2/test_modeling_tf_gpt2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt2/test_tokenization_gpt2.py b/tests/models/gpt2/test_tokenization_gpt2.py index 40e9f2fe48..0e954a8c6c 100644 --- a/tests/models/gpt2/test_tokenization_gpt2.py +++ b/tests/models/gpt2/test_tokenization_gpt2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt_bigcode/test_modeling_gpt_bigcode.py b/tests/models/gpt_bigcode/test_modeling_gpt_bigcode.py index 18b2e64088..67cfb40ea1 100644 --- a/tests/models/gpt_bigcode/test_modeling_gpt_bigcode.py +++ b/tests/models/gpt_bigcode/test_modeling_gpt_bigcode.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt_neo/test_modeling_flax_gpt_neo.py b/tests/models/gpt_neo/test_modeling_flax_gpt_neo.py index 170a261b41..abaadc2247 100644 --- a/tests/models/gpt_neo/test_modeling_flax_gpt_neo.py +++ b/tests/models/gpt_neo/test_modeling_flax_gpt_neo.py @@ -133,7 +133,7 @@ class FlaxGPTNeoModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, input_ids, attention_mask): @@ -166,7 +166,7 @@ class FlaxGPTNeoModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/gpt_neo/test_modeling_gpt_neo.py b/tests/models/gpt_neo/test_modeling_gpt_neo.py index 9a447e2cad..9384ab2f09 100644 --- a/tests/models/gpt_neo/test_modeling_gpt_neo.py +++ b/tests/models/gpt_neo/test_modeling_gpt_neo.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt_neox/test_modeling_gpt_neox.py b/tests/models/gpt_neox/test_modeling_gpt_neox.py index 45906d6077..a9d7e84dd0 100644 --- a/tests/models/gpt_neox/test_modeling_gpt_neox.py +++ b/tests/models/gpt_neox/test_modeling_gpt_neox.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py b/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py index 22bd647081..d8d2027863 100644 --- a/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py +++ b/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt_neox_japanese/test_tokenization_gpt_neox_japanese.py b/tests/models/gpt_neox_japanese/test_tokenization_gpt_neox_japanese.py index 6402c57956..483708c589 100644 --- a/tests/models/gpt_neox_japanese/test_tokenization_gpt_neox_japanese.py +++ b/tests/models/gpt_neox_japanese/test_tokenization_gpt_neox_japanese.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gpt_sw3/test_tokenization_gpt_sw3.py b/tests/models/gpt_sw3/test_tokenization_gpt_sw3.py index a13be778a6..4a1a3292c5 100644 --- a/tests/models/gpt_sw3/test_tokenization_gpt_sw3.py +++ b/tests/models/gpt_sw3/test_tokenization_gpt_sw3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Hugging Face inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gptj/test_modeling_flax_gptj.py b/tests/models/gptj/test_modeling_flax_gptj.py index 305a86ece1..f92c07ab6e 100644 --- a/tests/models/gptj/test_modeling_flax_gptj.py +++ b/tests/models/gptj/test_modeling_flax_gptj.py @@ -130,7 +130,7 @@ class FlaxGPTJModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, input_ids, attention_mask): @@ -163,7 +163,7 @@ class FlaxGPTJModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/gptj/test_modeling_gptj.py b/tests/models/gptj/test_modeling_gptj.py index ddc1521821..9614c5de1a 100644 --- a/tests/models/gptj/test_modeling_gptj.py +++ b/tests/models/gptj/test_modeling_gptj.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/gptj/test_modeling_tf_gptj.py b/tests/models/gptj/test_modeling_tf_gptj.py index 295c08aebb..2103dd9c26 100644 --- a/tests/models/gptj/test_modeling_tf_gptj.py +++ b/tests/models/gptj/test_modeling_tf_gptj.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/granite/test_modeling_granite.py b/tests/models/granite/test_modeling_granite.py index 8a37723958..d0ea3c35a9 100644 --- a/tests/models/granite/test_modeling_granite.py +++ b/tests/models/granite/test_modeling_granite.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/granitemoe/test_modeling_granitemoe.py b/tests/models/granitemoe/test_modeling_granitemoe.py index 7ed6f764f3..db43e10de1 100644 --- a/tests/models/granitemoe/test_modeling_granitemoe.py +++ b/tests/models/granitemoe/test_modeling_granitemoe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/granitemoeshared/test_modeling_granitemoeshared.py b/tests/models/granitemoeshared/test_modeling_granitemoeshared.py index cc71b17850..0ac6327448 100644 --- a/tests/models/granitemoeshared/test_modeling_granitemoeshared.py +++ b/tests/models/granitemoeshared/test_modeling_granitemoeshared.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/grounding_dino/test_image_processing_grounding_dino.py b/tests/models/grounding_dino/test_image_processing_grounding_dino.py index 4ac70a4e0f..1a0c27b422 100644 --- a/tests/models/grounding_dino/test_image_processing_grounding_dino.py +++ b/tests/models/grounding_dino/test_image_processing_grounding_dino.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -203,7 +202,7 @@ class GroundingDinoImageProcessingTest(AnnotationFormatTestMixin, ImageProcessin def test_call_pytorch_with_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -250,7 +249,7 @@ class GroundingDinoImageProcessingTest(AnnotationFormatTestMixin, ImageProcessin image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) annotations_0 = {"image_id": 39769, "annotations": target} @@ -369,7 +368,7 @@ class GroundingDinoImageProcessingTest(AnnotationFormatTestMixin, ImageProcessin def test_call_pytorch_with_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -423,7 +422,7 @@ class GroundingDinoImageProcessingTest(AnnotationFormatTestMixin, ImageProcessin image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) annotation_0 = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} diff --git a/tests/models/grounding_dino/test_modeling_grounding_dino.py b/tests/models/grounding_dino/test_modeling_grounding_dino.py index 88ba1caa2b..19a5054c98 100644 --- a/tests/models/grounding_dino/test_modeling_grounding_dino.py +++ b/tests/models/grounding_dino/test_modeling_grounding_dino.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/groupvit/test_modeling_groupvit.py b/tests/models/groupvit/test_modeling_groupvit.py index 3c48743a59..6226f6ff0f 100644 --- a/tests/models/groupvit/test_modeling_groupvit.py +++ b/tests/models/groupvit/test_modeling_groupvit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/groupvit/test_modeling_tf_groupvit.py b/tests/models/groupvit/test_modeling_tf_groupvit.py index 06c37dcd40..24ffc88a82 100644 --- a/tests/models/groupvit/test_modeling_tf_groupvit.py +++ b/tests/models/groupvit/test_modeling_tf_groupvit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/helium/test_modeling_helium.py b/tests/models/helium/test_modeling_helium.py index fb73211007..f4a555588e 100644 --- a/tests/models/helium/test_modeling_helium.py +++ b/tests/models/helium/test_modeling_helium.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/herbert/test_tokenization_herbert.py b/tests/models/herbert/test_tokenization_herbert.py index 36849bb698..6bd95000d6 100644 --- a/tests/models/herbert/test_tokenization_herbert.py +++ b/tests/models/herbert/test_tokenization_herbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors, Allegro.pl and The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/hiera/test_modeling_hiera.py b/tests/models/hiera/test_modeling_hiera.py index bbd35f29ef..7874c78d82 100644 --- a/tests/models/hiera/test_modeling_hiera.py +++ b/tests/models/hiera/test_modeling_hiera.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ import math import unittest -from typing import Dict, List, Tuple from transformers import HieraConfig from transformers.testing_utils import ( @@ -410,10 +408,10 @@ class HieraModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/hubert/test_modeling_hubert.py b/tests/models/hubert/test_modeling_hubert.py index 9f77379bef..800a35ab4a 100644 --- a/tests/models/hubert/test_modeling_hubert.py +++ b/tests/models/hubert/test_modeling_hubert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/hubert/test_modeling_tf_hubert.py b/tests/models/hubert/test_modeling_tf_hubert.py index 6372fc13a1..8d377ae885 100644 --- a/tests/models/hubert/test_modeling_tf_hubert.py +++ b/tests/models/hubert/test_modeling_tf_hubert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/ibert/test_modeling_ibert.py b/tests/models/ibert/test_modeling_ibert.py index 3918b3efea..9065a7046b 100644 --- a/tests/models/ibert/test_modeling_ibert.py +++ b/tests/models/ibert/test_modeling_ibert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics/test_image_processing_idefics.py b/tests/models/idefics/test_image_processing_idefics.py index 5b40a0393e..36a2ebd343 100644 --- a/tests/models/idefics/test_image_processing_idefics.py +++ b/tests/models/idefics/test_image_processing_idefics.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics/test_modeling_idefics.py b/tests/models/idefics/test_modeling_idefics.py index 2b591aa04f..169ec75d00 100644 --- a/tests/models/idefics/test_modeling_idefics.py +++ b/tests/models/idefics/test_modeling_idefics.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics/test_modeling_tf_idefics.py b/tests/models/idefics/test_modeling_tf_idefics.py index 3d2ba3f78c..bd7c9b06c2 100644 --- a/tests/models/idefics/test_modeling_tf_idefics.py +++ b/tests/models/idefics/test_modeling_tf_idefics.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics2/test_image_processing_idefics2.py b/tests/models/idefics2/test_image_processing_idefics2.py index bf9634b398..c389645020 100644 --- a/tests/models/idefics2/test_image_processing_idefics2.py +++ b/tests/models/idefics2/test_image_processing_idefics2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics2/test_modeling_idefics2.py b/tests/models/idefics2/test_modeling_idefics2.py index 98a0b2d50b..3c1ac9bb51 100644 --- a/tests/models/idefics2/test_modeling_idefics2.py +++ b/tests/models/idefics2/test_modeling_idefics2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics2/test_processor_idefics2.py b/tests/models/idefics2/test_processor_idefics2.py index d89004679a..f0b06470fe 100644 --- a/tests/models/idefics2/test_processor_idefics2.py +++ b/tests/models/idefics2/test_processor_idefics2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics3/test_image_processing_idefics3.py b/tests/models/idefics3/test_image_processing_idefics3.py index d5e3870006..01ea063aa3 100644 --- a/tests/models/idefics3/test_image_processing_idefics3.py +++ b/tests/models/idefics3/test_image_processing_idefics3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics3/test_modeling_idefics3.py b/tests/models/idefics3/test_modeling_idefics3.py index 9318f82d02..f1fcfd3943 100644 --- a/tests/models/idefics3/test_modeling_idefics3.py +++ b/tests/models/idefics3/test_modeling_idefics3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/idefics3/test_processor_idefics3.py b/tests/models/idefics3/test_processor_idefics3.py index 36c5d29484..c64e596bee 100644 --- a/tests/models/idefics3/test_processor_idefics3.py +++ b/tests/models/idefics3/test_processor_idefics3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/ijepa/test_modeling_ijepa.py b/tests/models/ijepa/test_modeling_ijepa.py index 4088f355a4..1049a4abeb 100644 --- a/tests/models/ijepa/test_modeling_ijepa.py +++ b/tests/models/ijepa/test_modeling_ijepa.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/imagegpt/test_image_processing_imagegpt.py b/tests/models/imagegpt/test_image_processing_imagegpt.py index d32e954cca..de29b8e29f 100644 --- a/tests/models/imagegpt/test_image_processing_imagegpt.py +++ b/tests/models/imagegpt/test_image_processing_imagegpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/imagegpt/test_modeling_imagegpt.py b/tests/models/imagegpt/test_modeling_imagegpt.py index b563dc69a7..98b1640d62 100644 --- a/tests/models/imagegpt/test_modeling_imagegpt.py +++ b/tests/models/imagegpt/test_modeling_imagegpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/informer/test_modeling_informer.py b/tests/models/informer/test_modeling_informer.py index 6b5a36e584..4940819771 100644 --- a/tests/models/informer/test_modeling_informer.py +++ b/tests/models/informer/test_modeling_informer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/instructblip/test_modeling_instructblip.py b/tests/models/instructblip/test_modeling_instructblip.py index f7c13dd09d..c795de7a0b 100644 --- a/tests/models/instructblip/test_modeling_instructblip.py +++ b/tests/models/instructblip/test_modeling_instructblip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/instructblipvideo/test_image_processing_instrictblipvideo.py b/tests/models/instructblipvideo/test_image_processing_instrictblipvideo.py index dacb922e72..d6e9900855 100644 --- a/tests/models/instructblipvideo/test_image_processing_instrictblipvideo.py +++ b/tests/models/instructblipvideo/test_image_processing_instrictblipvideo.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/instructblipvideo/test_modeling_instructblipvideo.py b/tests/models/instructblipvideo/test_modeling_instructblipvideo.py index e5cc00d92c..a4b7f25e34 100644 --- a/tests/models/instructblipvideo/test_modeling_instructblipvideo.py +++ b/tests/models/instructblipvideo/test_modeling_instructblipvideo.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/jamba/test_modeling_jamba.py b/tests/models/jamba/test_modeling_jamba.py index 0036c21521..67f9b30c85 100644 --- a/tests/models/jamba/test_modeling_jamba.py +++ b/tests/models/jamba/test_modeling_jamba.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/jetmoe/test_modeling_jetmoe.py b/tests/models/jetmoe/test_modeling_jetmoe.py index e2c1851333..d3b17c830f 100644 --- a/tests/models/jetmoe/test_modeling_jetmoe.py +++ b/tests/models/jetmoe/test_modeling_jetmoe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 JetMoe AI and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/kosmos2/test_modeling_kosmos2.py b/tests/models/kosmos2/test_modeling_kosmos2.py index 315130b232..c37d695c06 100644 --- a/tests/models/kosmos2/test_modeling_kosmos2.py +++ b/tests/models/kosmos2/test_modeling_kosmos2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 Microsoft Research and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/kosmos2/test_processor_kosmos2.py b/tests/models/kosmos2/test_processor_kosmos2.py index 0a34c39681..9a300719bc 100644 --- a/tests/models/kosmos2/test_processor_kosmos2.py +++ b/tests/models/kosmos2/test_processor_kosmos2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 Microsoft Research and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlm/test_modeling_layoutlm.py b/tests/models/layoutlm/test_modeling_layoutlm.py index 68605c1d6a..b6c820b9ac 100644 --- a/tests/models/layoutlm/test_modeling_layoutlm.py +++ b/tests/models/layoutlm/test_modeling_layoutlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 The Microsoft Research Asia LayoutLM Team Authors, The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlm/test_modeling_tf_layoutlm.py b/tests/models/layoutlm/test_modeling_tf_layoutlm.py index 14fc59ff71..f2690b14fb 100644 --- a/tests/models/layoutlm/test_modeling_tf_layoutlm.py +++ b/tests/models/layoutlm/test_modeling_tf_layoutlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 The Microsoft Research Asia LayoutLM Team Authors, The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlm/test_tokenization_layoutlm.py b/tests/models/layoutlm/test_tokenization_layoutlm.py index 7143d8b0e0..305dbcaa2e 100644 --- a/tests/models/layoutlm/test_tokenization_layoutlm.py +++ b/tests/models/layoutlm/test_tokenization_layoutlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 The Microsoft Research Asia LayoutLM Team Authors, The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py b/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py index 41cc9943cf..8bccb33217 100644 --- a/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_image_processing_layoutlmv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlmv2/test_modeling_layoutlmv2.py b/tests/models/layoutlmv2/test_modeling_layoutlmv2.py index ee62ed011b..accff4075b 100644 --- a/tests/models/layoutlmv2/test_modeling_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_modeling_layoutlmv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlmv2/test_processor_layoutlmv2.py b/tests/models/layoutlmv2/test_processor_layoutlmv2.py index a2676195ff..28b4d7a232 100644 --- a/tests/models/layoutlmv2/test_processor_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_processor_layoutlmv2.py @@ -17,7 +17,6 @@ import os import shutil import tempfile import unittest -from typing import List from transformers import PreTrainedTokenizer, PreTrainedTokenizerBase, PreTrainedTokenizerFast from transformers.models.layoutlmv2 import LayoutLMv2Processor, LayoutLMv2Tokenizer, LayoutLMv2TokenizerFast @@ -80,7 +79,7 @@ class LayoutLMv2ProcessorTest(ProcessorTesterMixin, unittest.TestCase): def get_rust_tokenizer(self, **kwargs) -> PreTrainedTokenizerFast: return self.rust_tokenizer_class.from_pretrained(self.tmpdirname, **kwargs) - def get_tokenizers(self, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(self, **kwargs) -> list[PreTrainedTokenizerBase]: return [self.get_tokenizer(**kwargs), self.get_rust_tokenizer(**kwargs)] def get_image_processor(self, **kwargs): diff --git a/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py b/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py index e2271d60c6..fcf46670db 100644 --- a/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +18,6 @@ import re import shutil import tempfile import unittest -from typing import List from parameterized import parameterized @@ -295,7 +293,7 @@ class LayoutLMv2TokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertEqual([e[0] for e in expected_results], tokens["offset_mapping"]) def test_add_special_tokens(self): - tokenizers: List[LayoutLMv2Tokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[LayoutLMv2Tokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): special_token = "[SPECIAL_TOKEN]" @@ -311,7 +309,7 @@ class LayoutLMv2TokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertTrue(special_token not in decoded) def test_add_tokens_tokenizer(self): - tokenizers: List[LayoutLMv2Tokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[LayoutLMv2Tokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): vocab_size = tokenizer.vocab_size diff --git a/tests/models/layoutlmv3/test_image_processing_layoutlmv3.py b/tests/models/layoutlmv3/test_image_processing_layoutlmv3.py index a6aebc88b2..7d302c5cdf 100644 --- a/tests/models/layoutlmv3/test_image_processing_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_image_processing_layoutlmv3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlmv3/test_modeling_layoutlmv3.py b/tests/models/layoutlmv3/test_modeling_layoutlmv3.py index af0301cf6b..7fa143d0d3 100644 --- a/tests/models/layoutlmv3/test_modeling_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_modeling_layoutlmv3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py b/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py index ad0528f8da..5ceea057bb 100644 --- a/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/layoutlmv3/test_processor_layoutlmv3.py b/tests/models/layoutlmv3/test_processor_layoutlmv3.py index e55b19ea44..cb10252763 100644 --- a/tests/models/layoutlmv3/test_processor_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_processor_layoutlmv3.py @@ -17,7 +17,6 @@ import os import shutil import tempfile import unittest -from typing import List from transformers import PreTrainedTokenizer, PreTrainedTokenizerBase, PreTrainedTokenizerFast from transformers.models.layoutlmv3 import LayoutLMv3Processor, LayoutLMv3Tokenizer, LayoutLMv3TokenizerFast @@ -93,7 +92,7 @@ class LayoutLMv3ProcessorTest(ProcessorTesterMixin, unittest.TestCase): def get_rust_tokenizer(self, **kwargs) -> PreTrainedTokenizerFast: return self.rust_tokenizer_class.from_pretrained(self.tmpdirname, **kwargs) - def get_tokenizers(self, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(self, **kwargs) -> list[PreTrainedTokenizerBase]: return [self.get_tokenizer(**kwargs), self.get_rust_tokenizer(**kwargs)] def get_image_processor(self, **kwargs): diff --git a/tests/models/layoutlmv3/test_tokenization_layoutlmv3.py b/tests/models/layoutlmv3/test_tokenization_layoutlmv3.py index 48e36411db..a1989d814a 100644 --- a/tests/models/layoutlmv3/test_tokenization_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_tokenization_layoutlmv3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +20,6 @@ import shutil import tempfile import unittest from functools import lru_cache -from typing import List from parameterized import parameterized @@ -189,7 +187,7 @@ class LayoutLMv3TokenizationTest(TokenizerTesterMixin, unittest.TestCase): assert encoded_pair == [0] + text + [2] + [2] + text_2 + [2] def test_add_special_tokens(self): - tokenizers: List[LayoutLMv3Tokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[LayoutLMv3Tokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): special_token = "[SPECIAL_TOKEN]" @@ -205,7 +203,7 @@ class LayoutLMv3TokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertTrue(special_token not in decoded) def test_add_tokens_tokenizer(self): - tokenizers: List[LayoutLMv3Tokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[LayoutLMv3Tokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): vocab_size = tokenizer.vocab_size diff --git a/tests/models/layoutxlm/test_processor_layoutxlm.py b/tests/models/layoutxlm/test_processor_layoutxlm.py index b970a3e526..278d46d2fc 100644 --- a/tests/models/layoutxlm/test_processor_layoutxlm.py +++ b/tests/models/layoutxlm/test_processor_layoutxlm.py @@ -17,7 +17,6 @@ import os import shutil import tempfile import unittest -from typing import List from transformers import PreTrainedTokenizer, PreTrainedTokenizerBase, PreTrainedTokenizerFast from transformers.models.layoutxlm import LayoutXLMProcessor, LayoutXLMTokenizer, LayoutXLMTokenizerFast @@ -73,7 +72,7 @@ class LayoutXLMProcessorTest(ProcessorTesterMixin, unittest.TestCase): def get_rust_tokenizer(self, **kwargs) -> PreTrainedTokenizerFast: return self.rust_tokenizer_class.from_pretrained(self.tokenizer_pretrained_name, **kwargs) - def get_tokenizers(self, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(self, **kwargs) -> list[PreTrainedTokenizerBase]: return [self.get_tokenizer(**kwargs), self.get_rust_tokenizer(**kwargs)] def get_image_processor(self, **kwargs): diff --git a/tests/models/layoutxlm/test_tokenization_layoutxlm.py b/tests/models/layoutxlm/test_tokenization_layoutxlm.py index 36f837a89f..2bd76954d6 100644 --- a/tests/models/layoutxlm/test_tokenization_layoutxlm.py +++ b/tests/models/layoutxlm/test_tokenization_layoutxlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,6 @@ import inspect import shutil import tempfile import unittest -from typing import List from parameterized import parameterized @@ -234,7 +232,7 @@ class LayoutXLMTokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertEqual([e[0] for e in expected_results], tokens["offset_mapping"]) def test_add_special_tokens(self): - tokenizers: List[LayoutXLMTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[LayoutXLMTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): special_token = "[SPECIAL_TOKEN]" @@ -250,7 +248,7 @@ class LayoutXLMTokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertTrue(special_token not in decoded) def test_add_tokens_tokenizer(self): - tokenizers: List[LayoutXLMTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[LayoutXLMTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): vocab_size = tokenizer.vocab_size diff --git a/tests/models/led/test_modeling_led.py b/tests/models/led/test_modeling_led.py index 4b9d2e283f..a80543ef25 100644 --- a/tests/models/led/test_modeling_led.py +++ b/tests/models/led/test_modeling_led.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 Iz Beltagy, Matthew E. Peters, Arman Cohan and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/led/test_modeling_tf_led.py b/tests/models/led/test_modeling_tf_led.py index 108d3f614f..e63b376d58 100644 --- a/tests/models/led/test_modeling_tf_led.py +++ b/tests/models/led/test_modeling_tf_led.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright Iz Beltagy, Matthew E. Peters, Arman Cohan and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/levit/test_image_processing_levit.py b/tests/models/levit/test_image_processing_levit.py index c04656ea8b..6a8f76a465 100644 --- a/tests/models/levit/test_image_processing_levit.py +++ b/tests/models/levit/test_image_processing_levit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/levit/test_modeling_levit.py b/tests/models/levit/test_modeling_levit.py index b35967a84e..f6226be1f8 100644 --- a/tests/models/levit/test_modeling_levit.py +++ b/tests/models/levit/test_modeling_levit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/lilt/test_modeling_lilt.py b/tests/models/lilt/test_modeling_lilt.py index 5ac02f9427..949649a503 100644 --- a/tests/models/lilt/test_modeling_lilt.py +++ b/tests/models/lilt/test_modeling_lilt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llama/test_modeling_flax_llama.py b/tests/models/llama/test_modeling_flax_llama.py index e4d9418bec..7091dadf58 100644 --- a/tests/models/llama/test_modeling_flax_llama.py +++ b/tests/models/llama/test_modeling_flax_llama.py @@ -135,7 +135,7 @@ class FlaxLlamaModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, input_ids, attention_mask): @@ -168,7 +168,7 @@ class FlaxLlamaModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/llama/test_modeling_llama.py b/tests/models/llama/test_modeling_llama.py index 202a8687f8..fe843938cf 100644 --- a/tests/models/llama/test_modeling_llama.py +++ b/tests/models/llama/test_modeling_llama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llama/test_tokenization_llama.py b/tests/models/llama/test_tokenization_llama.py index 2c0e15bffd..a69ea3948e 100644 --- a/tests/models/llama/test_tokenization_llama.py +++ b/tests/models/llama/test_tokenization_llama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -417,14 +416,14 @@ class LlamaIntegrationTest(unittest.TestCase): with tempfile.TemporaryDirectory() as dirname: self.rust_tokenizer.save_pretrained(dirname) - with open(os.path.join(dirname, "tokenizer.json"), "r") as f: + with open(os.path.join(dirname, "tokenizer.json")) as f: old_serialized = f.read() new_tokenizer = convert_slow_tokenizer(self.tokenizer) with tempfile.NamedTemporaryFile() as f: new_tokenizer.save(f.name) # Re-opening since `f` is in bytes. - new_serialized = open(f.name, "r").read() + new_serialized = open(f.name).read() with open("out_tokenizer.json", "w") as g: g.write(new_serialized) diff --git a/tests/models/llama4/test_image_processing_llama4.py b/tests/models/llama4/test_image_processing_llama4.py index 93f34d2548..dfc39f4ff4 100644 --- a/tests/models/llama4/test_image_processing_llama4.py +++ b/tests/models/llama4/test_image_processing_llama4.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llama4/test_modeling_llama4.py b/tests/models/llama4/test_modeling_llama4.py index 65672993a0..f3f1d137d1 100644 --- a/tests/models/llama4/test_modeling_llama4.py +++ b/tests/models/llama4/test_modeling_llama4.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava/test_image_processing_llava.py b/tests/models/llava/test_image_processing_llava.py index 9bd9fcaa7e..b91c44d82b 100644 --- a/tests/models/llava/test_image_processing_llava.py +++ b/tests/models/llava/test_image_processing_llava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,7 @@ import unittest -from typing import Tuple, Union +from typing import Union import numpy as np @@ -152,7 +151,7 @@ class LlavaImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase): # taken from original implementation: https://github.com/haotian-liu/LLaVA/blob/c121f0432da27facab705978f83c4ada465e46fd/llava/mm_utils.py#L152 def pad_to_square_original( - image: Image.Image, background_color: Union[int, Tuple[int, int, int]] = 0 + image: Image.Image, background_color: Union[int, tuple[int, int, int]] = 0 ) -> Image.Image: width, height = image.size if width == height: diff --git a/tests/models/llava/test_modeling_llava.py b/tests/models/llava/test_modeling_llava.py index cf709a2807..4747acf751 100644 --- a/tests/models/llava/test_modeling_llava.py +++ b/tests/models/llava/test_modeling_llava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_next/test_image_processing_llava_next.py b/tests/models/llava_next/test_image_processing_llava_next.py index 957a5c3abd..d3229c1bcd 100644 --- a/tests/models/llava_next/test_image_processing_llava_next.py +++ b/tests/models/llava_next/test_image_processing_llava_next.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_next/test_modeling_llava_next.py b/tests/models/llava_next/test_modeling_llava_next.py index 99bfdb632d..dcba5fb8af 100644 --- a/tests/models/llava_next/test_modeling_llava_next.py +++ b/tests/models/llava_next/test_modeling_llava_next.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_next_video/test_image_processing_llava_next_video.py b/tests/models/llava_next_video/test_image_processing_llava_next_video.py index 6a0cadc93c..0a7cc1eace 100644 --- a/tests/models/llava_next_video/test_image_processing_llava_next_video.py +++ b/tests/models/llava_next_video/test_image_processing_llava_next_video.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_next_video/test_modeling_llava_next_video.py b/tests/models/llava_next_video/test_modeling_llava_next_video.py index 6e17836f5c..23efdb7de0 100644 --- a/tests/models/llava_next_video/test_modeling_llava_next_video.py +++ b/tests/models/llava_next_video/test_modeling_llava_next_video.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_next_video/test_processor_llava_next_video.py b/tests/models/llava_next_video/test_processor_llava_next_video.py index 764c944bac..aa2b3045a5 100644 --- a/tests/models/llava_next_video/test_processor_llava_next_video.py +++ b/tests/models/llava_next_video/test_processor_llava_next_video.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_onevision/test_image_processing_llava_onevision.py b/tests/models/llava_onevision/test_image_processing_llava_onevision.py index 3fbd358f97..d1fda02910 100644 --- a/tests/models/llava_onevision/test_image_processing_llava_onevision.py +++ b/tests/models/llava_onevision/test_image_processing_llava_onevision.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/llava_onevision/test_modeling_llava_onevision.py b/tests/models/llava_onevision/test_modeling_llava_onevision.py index b6eb87f95f..f311f2b455 100644 --- a/tests/models/llava_onevision/test_modeling_llava_onevision.py +++ b/tests/models/llava_onevision/test_modeling_llava_onevision.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/longformer/test_modeling_longformer.py b/tests/models/longformer/test_modeling_longformer.py index 304a0e4744..e535e5c208 100644 --- a/tests/models/longformer/test_modeling_longformer.py +++ b/tests/models/longformer/test_modeling_longformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/longformer/test_modeling_tf_longformer.py b/tests/models/longformer/test_modeling_tf_longformer.py index 7e0c57c49a..19b4197943 100644 --- a/tests/models/longformer/test_modeling_tf_longformer.py +++ b/tests/models/longformer/test_modeling_tf_longformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/longformer/test_tokenization_longformer.py b/tests/models/longformer/test_tokenization_longformer.py index 303a9ae2d0..da66a109ac 100644 --- a/tests/models/longformer/test_tokenization_longformer.py +++ b/tests/models/longformer/test_tokenization_longformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Tsimur Hadeliya. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -140,7 +139,7 @@ class LongformerTokenizationTest(TokenizerTesterMixin, unittest.TestCase): tokenizer = self.get_tokenizer() sequence = "Encode this sequence." - space_encoding = tokenizer.byte_encoder[" ".encode("utf-8")[0]] + space_encoding = tokenizer.byte_encoder[b" "[0]] # Testing encoder arguments encoded = tokenizer.encode(sequence, add_special_tokens=False, add_prefix_space=False) diff --git a/tests/models/longt5/test_modeling_flax_longt5.py b/tests/models/longt5/test_modeling_flax_longt5.py index ec5432f9ef..e4f872bd43 100644 --- a/tests/models/longt5/test_modeling_flax_longt5.py +++ b/tests/models/longt5/test_modeling_flax_longt5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Google LongT5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -208,7 +207,7 @@ class FlaxLongT5ModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def prepare_config_and_inputs_for_common(self): diff --git a/tests/models/longt5/test_modeling_longt5.py b/tests/models/longt5/test_modeling_longt5.py index 06bb76b74d..d14be82431 100644 --- a/tests/models/longt5/test_modeling_longt5.py +++ b/tests/models/longt5/test_modeling_longt5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Google LongT5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/luke/test_modeling_luke.py b/tests/models/luke/test_modeling_luke.py index 8864e5687e..d255a607c5 100644 --- a/tests/models/luke/test_modeling_luke.py +++ b/tests/models/luke/test_modeling_luke.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/luke/test_tokenization_luke.py b/tests/models/luke/test_tokenization_luke.py index b935f3e49c..f5d823e3bc 100644 --- a/tests/models/luke/test_tokenization_luke.py +++ b/tests/models/luke/test_tokenization_luke.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ import unittest from functools import lru_cache -from typing import Tuple from transformers import AddedToken, LukeTokenizer from transformers.testing_utils import get_tests_dir, require_torch, slow @@ -90,7 +88,7 @@ class LukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): self.assertEqual(encoded_sentence, encoded_text_from_decode) self.assertEqual(encoded_pair, encoded_pair_from_decode) - def get_clean_sequence(self, tokenizer, max_length=20) -> Tuple[str, list]: + def get_clean_sequence(self, tokenizer, max_length=20) -> tuple[str, list]: txt = "Beyonce lives in Los Angeles" ids = tokenizer.encode(txt, add_special_tokens=False) return txt, ids @@ -99,7 +97,7 @@ class LukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): tokenizer = self.get_tokenizer() sequence = "Encode this sequence." - space_encoding = tokenizer.byte_encoder[" ".encode("utf-8")[0]] + space_encoding = tokenizer.byte_encoder[b" "[0]] # Testing encoder arguments encoded = tokenizer.encode(sequence, add_special_tokens=False, add_prefix_space=False) @@ -141,7 +139,7 @@ class LukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): def test_embeded_special_tokens(self): for tokenizer, pretrained_name, kwargs in self.tokenizers_list: - with self.subTest("{} ({})".format(tokenizer.__class__.__name__, pretrained_name)): + with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"): tokenizer_r = self.get_rust_tokenizer(pretrained_name, **kwargs) tokenizer_p = self.get_tokenizer(pretrained_name, **kwargs) sentence = "A, AllenNLP sentence." diff --git a/tests/models/lxmert/test_modeling_lxmert.py b/tests/models/lxmert/test_modeling_lxmert.py index 308662335d..6b3953da70 100644 --- a/tests/models/lxmert/test_modeling_lxmert.py +++ b/tests/models/lxmert/test_modeling_lxmert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 LXMERT Authors, The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/lxmert/test_modeling_tf_lxmert.py b/tests/models/lxmert/test_modeling_tf_lxmert.py index d6728f4cc3..27fa146fb0 100644 --- a/tests/models/lxmert/test_modeling_tf_lxmert.py +++ b/tests/models/lxmert/test_modeling_tf_lxmert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/lxmert/test_tokenization_lxmert.py b/tests/models/lxmert/test_tokenization_lxmert.py index b634d259ed..0b4121b857 100644 --- a/tests/models/lxmert/test_tokenization_lxmert.py +++ b/tests/models/lxmert/test_tokenization_lxmert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 LXMERT Authors, The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/m2m_100/test_modeling_m2m_100.py b/tests/models/m2m_100/test_modeling_m2m_100.py index f70cde6133..1c33150ada 100644 --- a/tests/models/m2m_100/test_modeling_m2m_100.py +++ b/tests/models/m2m_100/test_modeling_m2m_100.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mamba/test_modeling_mamba.py b/tests/models/mamba/test_modeling_mamba.py index 02ecbbfd3c..840493648f 100644 --- a/tests/models/mamba/test_modeling_mamba.py +++ b/tests/models/mamba/test_modeling_mamba.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ import math import unittest -from typing import Dict, List, Tuple from unittest.util import safe_repr from parameterized import parameterized @@ -275,7 +273,7 @@ class MambaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixi is_inside_interval = (min_value >= expected_min) and (max_value <= expected_max) if not is_inside_interval: - standardMsg = "%s not found in %s" % (safe_repr(member), safe_repr(container)) + standardMsg = f"{safe_repr(member)} not found in {safe_repr(container)}" self.fail(self._formatMessage(msg, standardMsg)) def test_config(self): @@ -367,10 +365,10 @@ class MambaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixi if isinstance(tuple_object, MambaCache): # MODIFIED PART START recursive_check(tuple_object.conv_states, dict_object.conv_states) recursive_check(tuple_object.ssm_states, dict_object.ssm_states) - elif isinstance(tuple_object, (List, Tuple)): # MODIFIED PART END + elif isinstance(tuple_object, (list, tuple)): # MODIFIED PART END for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/mamba2/test_modeling_mamba2.py b/tests/models/mamba2/test_modeling_mamba2.py index 0fae7e830c..d55655c6ac 100644 --- a/tests/models/mamba2/test_modeling_mamba2.py +++ b/tests/models/mamba2/test_modeling_mamba2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ import unittest -from typing import Dict, List, Tuple from parameterized import parameterized @@ -271,10 +269,10 @@ class Mamba2ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMix if isinstance(tuple_object, Mamba2Cache): # MODIFIED PART START recursive_check(tuple_object.conv_states, dict_object.conv_states) recursive_check(tuple_object.ssm_states, dict_object.ssm_states) - elif isinstance(tuple_object, (List, Tuple)): # MODIFIED PART END + elif isinstance(tuple_object, (list, tuple)): # MODIFIED PART END for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/marian/test_modeling_flax_marian.py b/tests/models/marian/test_modeling_flax_marian.py index 4353bd1732..73cd489761 100644 --- a/tests/models/marian/test_modeling_flax_marian.py +++ b/tests/models/marian/test_modeling_flax_marian.py @@ -176,7 +176,7 @@ class FlaxMarianModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -222,7 +222,7 @@ class FlaxMarianModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/marian/test_modeling_marian.py b/tests/models/marian/test_modeling_marian.py index 8a1e2b4a33..52f2232ee6 100644 --- a/tests/models/marian/test_modeling_marian.py +++ b/tests/models/marian/test_modeling_marian.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/marian/test_modeling_tf_marian.py b/tests/models/marian/test_modeling_tf_marian.py index 0613a10e4d..d6f0d06405 100644 --- a/tests/models/marian/test_modeling_tf_marian.py +++ b/tests/models/marian/test_modeling_tf_marian.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/marian/test_tokenization_marian.py b/tests/models/marian/test_tokenization_marian.py index 0381466360..45fee4f1fe 100644 --- a/tests/models/marian/test_tokenization_marian.py +++ b/tests/models/marian/test_tokenization_marian.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Huggingface # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/markuplm/test_feature_extraction_markuplm.py b/tests/models/markuplm/test_feature_extraction_markuplm.py index 381483d655..79515fe475 100644 --- a/tests/models/markuplm/test_feature_extraction_markuplm.py +++ b/tests/models/markuplm/test_feature_extraction_markuplm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/markuplm/test_modeling_markuplm.py b/tests/models/markuplm/test_modeling_markuplm.py index 7e2ce0b7c1..b1c31f5e4b 100644 --- a/tests/models/markuplm/test_modeling_markuplm.py +++ b/tests/models/markuplm/test_modeling_markuplm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/markuplm/test_processor_markuplm.py b/tests/models/markuplm/test_processor_markuplm.py index aa5cb6253f..444651dc3d 100644 --- a/tests/models/markuplm/test_processor_markuplm.py +++ b/tests/models/markuplm/test_processor_markuplm.py @@ -17,7 +17,6 @@ import os import shutil import tempfile import unittest -from typing import List from transformers import ( MarkupLMProcessor, @@ -75,7 +74,7 @@ class MarkupLMProcessorTest(unittest.TestCase): def get_rust_tokenizer(self, **kwargs) -> PreTrainedTokenizerFast: return self.rust_tokenizer_class.from_pretrained(self.tmpdirname, **kwargs) - def get_tokenizers(self, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(self, **kwargs) -> list[PreTrainedTokenizerBase]: return [self.get_tokenizer(**kwargs), self.get_rust_tokenizer(**kwargs)] def get_feature_extractor(self, **kwargs): diff --git a/tests/models/markuplm/test_tokenization_markuplm.py b/tests/models/markuplm/test_tokenization_markuplm.py index c7cb39964f..3e49516cd6 100644 --- a/tests/models/markuplm/test_tokenization_markuplm.py +++ b/tests/models/markuplm/test_tokenization_markuplm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +19,6 @@ import re import shutil import tempfile import unittest -from typing import List from parameterized import parameterized @@ -114,7 +112,7 @@ class MarkupLMTokenizationTest(TokenizerTesterMixin, unittest.TestCase): return input_text, output_text def test_add_special_tokens(self): - tokenizers: List[MarkupLMTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[MarkupLMTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): special_token = "[SPECIAL_TOKEN]" @@ -130,7 +128,7 @@ class MarkupLMTokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertTrue(special_token not in decoded) def test_add_tokens_tokenizer(self): - tokenizers: List[MarkupLMTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[MarkupLMTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): vocab_size = tokenizer.vocab_size diff --git a/tests/models/mask2former/test_image_processing_mask2former.py b/tests/models/mask2former/test_image_processing_mask2former.py index f2c5cd7794..457f5ad0af 100644 --- a/tests/models/mask2former/test_image_processing_mask2former.py +++ b/tests/models/mask2former/test_image_processing_mask2former.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mask2former/test_modeling_mask2former.py b/tests/models/mask2former/test_modeling_mask2former.py index b1fecd9253..475395c11f 100644 --- a/tests/models/mask2former/test_modeling_mask2former.py +++ b/tests/models/mask2former/test_modeling_mask2former.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/maskformer/test_image_processing_maskformer.py b/tests/models/maskformer/test_image_processing_maskformer.py index d97522261c..be31e4f692 100644 --- a/tests/models/maskformer/test_image_processing_maskformer.py +++ b/tests/models/maskformer/test_image_processing_maskformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/maskformer/test_modeling_maskformer.py b/tests/models/maskformer/test_modeling_maskformer.py index 284cdb5f49..5e12d5ddc5 100644 --- a/tests/models/maskformer/test_modeling_maskformer.py +++ b/tests/models/maskformer/test_modeling_maskformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/maskformer/test_modeling_maskformer_swin.py b/tests/models/maskformer/test_modeling_maskformer_swin.py index 6125c2854f..978596bf6a 100644 --- a/tests/models/maskformer/test_modeling_maskformer_swin.py +++ b/tests/models/maskformer/test_modeling_maskformer_swin.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ import collections import unittest -from typing import Dict, List, Tuple from transformers import MaskFormerSwinConfig from transformers.testing_utils import require_torch, require_torch_multi_gpu, torch_device @@ -335,10 +333,10 @@ class MaskFormerSwinModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.Te dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/mbart/test_modeling_flax_mbart.py b/tests/models/mbart/test_modeling_flax_mbart.py index bacecec857..eaeea3f50f 100644 --- a/tests/models/mbart/test_modeling_flax_mbart.py +++ b/tests/models/mbart/test_modeling_flax_mbart.py @@ -185,7 +185,7 @@ class FlaxMBartModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -231,7 +231,7 @@ class FlaxMBartModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/mbart/test_modeling_mbart.py b/tests/models/mbart/test_modeling_mbart.py index 6920ea9b74..b80d11a865 100644 --- a/tests/models/mbart/test_modeling_mbart.py +++ b/tests/models/mbart/test_modeling_mbart.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mbart/test_modeling_tf_mbart.py b/tests/models/mbart/test_modeling_tf_mbart.py index d2a672c791..a768c63516 100644 --- a/tests/models/mbart/test_modeling_tf_mbart.py +++ b/tests/models/mbart/test_modeling_tf_mbart.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/megatron_bert/test_modeling_megatron_bert.py b/tests/models/megatron_bert/test_modeling_megatron_bert.py index f201c0ea93..f8cb9088a6 100644 --- a/tests/models/megatron_bert/test_modeling_megatron_bert.py +++ b/tests/models/megatron_bert/test_modeling_megatron_bert.py @@ -381,5 +381,5 @@ class MegatronBertModelIntegrationTests(unittest.TestCase): for jj in range(3): a = output[0, ii, jj] b = expected[3 * ii + jj] - msg = "ii={} jj={} a={} b={}".format(ii, jj, a, b) + msg = f"ii={ii} jj={jj} a={a} b={b}" self.assertTrue(math.isclose(a, b, rel_tol=TOLERANCE, abs_tol=TOLERANCE), msg=msg) diff --git a/tests/models/megatron_gpt2/test_modeling_megatron_gpt2.py b/tests/models/megatron_gpt2/test_modeling_megatron_gpt2.py index 47b8def921..18ac40b09a 100644 --- a/tests/models/megatron_gpt2/test_modeling_megatron_gpt2.py +++ b/tests/models/megatron_gpt2/test_modeling_megatron_gpt2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mgp_str/test_modeling_mgp_str.py b/tests/models/mgp_str/test_modeling_mgp_str.py index 849eb90a75..586e9f0bc4 100644 --- a/tests/models/mgp_str/test_modeling_mgp_str.py +++ b/tests/models/mgp_str/test_modeling_mgp_str.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mgp_str/test_processor_mgp_str.py b/tests/models/mgp_str/test_processor_mgp_str.py index f42dfb2661..ccfb6dba68 100644 --- a/tests/models/mgp_str/test_processor_mgp_str.py +++ b/tests/models/mgp_str/test_processor_mgp_str.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mgp_str/test_tokenization_mgp_str.py b/tests/models/mgp_str/test_tokenization_mgp_str.py index 2d021606ff..5707552dc8 100644 --- a/tests/models/mgp_str/test_tokenization_mgp_str.py +++ b/tests/models/mgp_str/test_tokenization_mgp_str.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mimi/test_modeling_mimi.py b/tests/models/mimi/test_modeling_mimi.py index 1cf819d401..bf48f34ce1 100644 --- a/tests/models/mimi/test_modeling_mimi.py +++ b/tests/models/mimi/test_modeling_mimi.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mistral/test_modeling_flax_mistral.py b/tests/models/mistral/test_modeling_flax_mistral.py index 14c91be258..1993c58366 100644 --- a/tests/models/mistral/test_modeling_flax_mistral.py +++ b/tests/models/mistral/test_modeling_flax_mistral.py @@ -145,7 +145,7 @@ class FlaxMistralModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") # Copied from tests.models.gpt_neo.test_modeling_flax_gpt_neo.FlaxGPTNeoModelTester.check_use_cache_forward_with_attn_mask @@ -179,7 +179,7 @@ class FlaxMistralModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/mistral/test_modeling_mistral.py b/tests/models/mistral/test_modeling_mistral.py index be82cbc796..ead979352a 100644 --- a/tests/models/mistral/test_modeling_mistral.py +++ b/tests/models/mistral/test_modeling_mistral.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 Mistral AI and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mistral/test_modeling_tf_mistral.py b/tests/models/mistral/test_modeling_tf_mistral.py index a45935e978..beff383a98 100644 --- a/tests/models/mistral/test_modeling_tf_mistral.py +++ b/tests/models/mistral/test_modeling_tf_mistral.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 Mistral AI and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mistral3/test_modeling_mistral3.py b/tests/models/mistral3/test_modeling_mistral3.py index 58096b5db7..2555126dba 100644 --- a/tests/models/mistral3/test_modeling_mistral3.py +++ b/tests/models/mistral3/test_modeling_mistral3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mistral3/test_processor_mistral3.py b/tests/models/mistral3/test_processor_mistral3.py index 916ba668f0..fa29d15f86 100644 --- a/tests/models/mistral3/test_processor_mistral3.py +++ b/tests/models/mistral3/test_processor_mistral3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mixtral/test_modeling_mixtral.py b/tests/models/mixtral/test_modeling_mixtral.py index 1c12cbc250..b4b3b38edf 100644 --- a/tests/models/mixtral/test_modeling_mixtral.py +++ b/tests/models/mixtral/test_modeling_mixtral.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mllama/test_image_processing_mllama.py b/tests/models/mllama/test_image_processing_mllama.py index 4b7fbcb81d..6a6581da9b 100644 --- a/tests/models/mllama/test_image_processing_mllama.py +++ b/tests/models/mllama/test_image_processing_mllama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mllama/test_modeling_mllama.py b/tests/models/mllama/test_modeling_mllama.py index ae28bd6697..711101f766 100644 --- a/tests/models/mllama/test_modeling_mllama.py +++ b/tests/models/mllama/test_modeling_mllama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mllama/test_processor_mllama.py b/tests/models/mllama/test_processor_mllama.py index bbc1d3dfc8..828fa35a9a 100644 --- a/tests/models/mllama/test_processor_mllama.py +++ b/tests/models/mllama/test_processor_mllama.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mluke/test_tokenization_mluke.py b/tests/models/mluke/test_tokenization_mluke.py index a86ea690a4..c9a6a44e29 100644 --- a/tests/models/mluke/test_tokenization_mluke.py +++ b/tests/models/mluke/test_tokenization_mluke.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ import unittest from functools import lru_cache -from typing import Tuple from transformers.models.mluke.tokenization_mluke import MLukeTokenizer from transformers.testing_utils import get_tests_dir, require_torch, slow @@ -93,7 +91,7 @@ class MLukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): self.assertEqual(encoded_sentence, encoded_text_from_decode) self.assertEqual(encoded_pair, encoded_pair_from_decode) - def get_clean_sequence(self, tokenizer, max_length=20) -> Tuple[str, list]: + def get_clean_sequence(self, tokenizer, max_length=20) -> tuple[str, list]: txt = "Beyonce lives in Los Angeles" ids = tokenizer.encode(txt, add_special_tokens=False) return txt, ids @@ -104,7 +102,7 @@ class MLukeTokenizerTest(TokenizerTesterMixin, unittest.TestCase): def test_embeded_special_tokens(self): for tokenizer, pretrained_name, kwargs in self.tokenizers_list: - with self.subTest("{} ({})".format(tokenizer.__class__.__name__, pretrained_name)): + with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"): tokenizer_r = self.get_rust_tokenizer(pretrained_name, **kwargs) tokenizer_p = self.get_tokenizer(pretrained_name, **kwargs) sentence = "A, AllenNLP sentence." diff --git a/tests/models/mobilebert/test_modeling_mobilebert.py b/tests/models/mobilebert/test_modeling_mobilebert.py index d2bc11d09f..126631fd9c 100644 --- a/tests/models/mobilebert/test_modeling_mobilebert.py +++ b/tests/models/mobilebert/test_modeling_mobilebert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilebert/test_modeling_tf_mobilebert.py b/tests/models/mobilebert/test_modeling_tf_mobilebert.py index bf1ad0b1d1..93a0ccad1f 100644 --- a/tests/models/mobilebert/test_modeling_tf_mobilebert.py +++ b/tests/models/mobilebert/test_modeling_tf_mobilebert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilebert/test_tokenization_mobilebert.py b/tests/models/mobilebert/test_tokenization_mobilebert.py index e0f4bff647..5c344f9d43 100644 --- a/tests/models/mobilebert/test_tokenization_mobilebert.py +++ b/tests/models/mobilebert/test_tokenization_mobilebert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Leon Derczynski. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilenet_v1/test_image_processing_mobilenet_v1.py b/tests/models/mobilenet_v1/test_image_processing_mobilenet_v1.py index c6553d445b..30d0146692 100644 --- a/tests/models/mobilenet_v1/test_image_processing_mobilenet_v1.py +++ b/tests/models/mobilenet_v1/test_image_processing_mobilenet_v1.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py b/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py index 9488700193..7c05d4b41c 100644 --- a/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py +++ b/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilenet_v2/test_image_processing_mobilenet_v2.py b/tests/models/mobilenet_v2/test_image_processing_mobilenet_v2.py index cf583e0175..ed4331de16 100644 --- a/tests/models/mobilenet_v2/test_image_processing_mobilenet_v2.py +++ b/tests/models/mobilenet_v2/test_image_processing_mobilenet_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py b/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py index b5a12edd7b..13c7698af5 100644 --- a/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py +++ b/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilevit/test_image_processing_mobilevit.py b/tests/models/mobilevit/test_image_processing_mobilevit.py index 976c8c68e9..837d5ccf9c 100644 --- a/tests/models/mobilevit/test_image_processing_mobilevit.py +++ b/tests/models/mobilevit/test_image_processing_mobilevit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilevit/test_modeling_mobilevit.py b/tests/models/mobilevit/test_modeling_mobilevit.py index b67abce934..f6cc09eddd 100644 --- a/tests/models/mobilevit/test_modeling_mobilevit.py +++ b/tests/models/mobilevit/test_modeling_mobilevit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilevit/test_modeling_tf_mobilevit.py b/tests/models/mobilevit/test_modeling_tf_mobilevit.py index 61967ec341..13e3ab092b 100644 --- a/tests/models/mobilevit/test_modeling_tf_mobilevit.py +++ b/tests/models/mobilevit/test_modeling_tf_mobilevit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mobilevitv2/test_modeling_mobilevitv2.py b/tests/models/mobilevitv2/test_modeling_mobilevitv2.py index 70fc70124f..7a0433f123 100644 --- a/tests/models/mobilevitv2/test_modeling_mobilevitv2.py +++ b/tests/models/mobilevitv2/test_modeling_mobilevitv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/modernbert/test_modeling_modernbert.py b/tests/models/modernbert/test_modeling_modernbert.py index 82a0f85052..187fbcb838 100644 --- a/tests/models/modernbert/test_modeling_modernbert.py +++ b/tests/models/modernbert/test_modeling_modernbert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -372,7 +371,7 @@ class ModernBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCa config = ModernBertConfig(reference_compile=True) with tempfile.TemporaryDirectory() as tmpdirname: config.save_pretrained(tmpdirname) - with open(os.path.join(tmpdirname, "config.json"), "r") as f: + with open(os.path.join(tmpdirname, "config.json")) as f: config_dict = json.load(f) self.assertNotIn("reference_compile", config_dict) diff --git a/tests/models/moonshine/test_modeling_moonshine.py b/tests/models/moonshine/test_modeling_moonshine.py index d5f6ed6396..abc45a491f 100644 --- a/tests/models/moonshine/test_modeling_moonshine.py +++ b/tests/models/moonshine/test_modeling_moonshine.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/moshi/test_modeling_moshi.py b/tests/models/moshi/test_modeling_moshi.py index 2f92e74d5a..5d7d83a38e 100644 --- a/tests/models/moshi/test_modeling_moshi.py +++ b/tests/models/moshi/test_modeling_moshi.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/moshi/test_tokenization_moshi.py b/tests/models/moshi/test_tokenization_moshi.py index 740cfd55d3..d1e5287b23 100644 --- a/tests/models/moshi/test_tokenization_moshi.py +++ b/tests/models/moshi/test_tokenization_moshi.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mpnet/test_modeling_mpnet.py b/tests/models/mpnet/test_modeling_mpnet.py index e71ec7566d..c41a906701 100644 --- a/tests/models/mpnet/test_modeling_mpnet.py +++ b/tests/models/mpnet/test_modeling_mpnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team, Microsoft Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mpnet/test_modeling_tf_mpnet.py b/tests/models/mpnet/test_modeling_tf_mpnet.py index b27b33d810..4a9ea86588 100644 --- a/tests/models/mpnet/test_modeling_tf_mpnet.py +++ b/tests/models/mpnet/test_modeling_tf_mpnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team, Microsoft Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mpnet/test_tokenization_mpnet.py b/tests/models/mpnet/test_tokenization_mpnet.py index 2b934a9ed6..c1e3809817 100644 --- a/tests/models/mpnet/test_tokenization_mpnet.py +++ b/tests/models/mpnet/test_tokenization_mpnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team, Microsoft Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mpt/test_modeling_mpt.py b/tests/models/mpt/test_modeling_mpt.py index cad2f88e23..896048538c 100644 --- a/tests/models/mpt/test_modeling_mpt.py +++ b/tests/models/mpt/test_modeling_mpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mra/test_modeling_mra.py b/tests/models/mra/test_modeling_mra.py index bf87d39085..ccb725baa7 100644 --- a/tests/models/mra/test_modeling_mra.py +++ b/tests/models/mra/test_modeling_mra.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mt5/test_modeling_tf_mt5.py b/tests/models/mt5/test_modeling_tf_mt5.py index facb63dd79..87249dc2a6 100644 --- a/tests/models/mt5/test_modeling_tf_mt5.py +++ b/tests/models/mt5/test_modeling_tf_mt5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/musicgen/test_modeling_musicgen.py b/tests/models/musicgen/test_modeling_musicgen.py index 9d49e1b6c5..1df5ec6ab0 100644 --- a/tests/models/musicgen/test_modeling_musicgen.py +++ b/tests/models/musicgen/test_modeling_musicgen.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/musicgen_melody/test_feature_extraction_musicgen_melody.py b/tests/models/musicgen_melody/test_feature_extraction_musicgen_melody.py index bdd1cb1e12..085fcc7683 100644 --- a/tests/models/musicgen_melody/test_feature_extraction_musicgen_melody.py +++ b/tests/models/musicgen_melody/test_feature_extraction_musicgen_melody.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/musicgen_melody/test_modeling_musicgen_melody.py b/tests/models/musicgen_melody/test_modeling_musicgen_melody.py index a979fb8f66..7501d83717 100644 --- a/tests/models/musicgen_melody/test_modeling_musicgen_melody.py +++ b/tests/models/musicgen_melody/test_modeling_musicgen_melody.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/mvp/test_modeling_mvp.py b/tests/models/mvp/test_modeling_mvp.py index 52734b2eb8..9ee1077d7d 100644 --- a/tests/models/mvp/test_modeling_mvp.py +++ b/tests/models/mvp/test_modeling_mvp.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/myt5/test_tokenization_myt5.py b/tests/models/myt5/test_tokenization_myt5.py index aab67978f2..b4bf638c62 100644 --- a/tests/models/myt5/test_tokenization_myt5.py +++ b/tests/models/myt5/test_tokenization_myt5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/nemotron/test_modeling_nemotron.py b/tests/models/nemotron/test_modeling_nemotron.py index fd905f8e0c..58c36b615f 100644 --- a/tests/models/nemotron/test_modeling_nemotron.py +++ b/tests/models/nemotron/test_modeling_nemotron.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. team. All rights reserved. # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. # diff --git a/tests/models/nllb_moe/test_modeling_nllb_moe.py b/tests/models/nllb_moe/test_modeling_nllb_moe.py index 8aee844b47..e79a96d816 100644 --- a/tests/models/nllb_moe/test_modeling_nllb_moe.py +++ b/tests/models/nllb_moe/test_modeling_nllb_moe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/nougat/test_image_processing_nougat.py b/tests/models/nougat/test_image_processing_nougat.py index 69382a1c3f..1757bcffff 100644 --- a/tests/models/nougat/test_image_processing_nougat.py +++ b/tests/models/nougat/test_image_processing_nougat.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/nougat/test_tokenization_nougat.py b/tests/models/nougat/test_tokenization_nougat.py index c5da1f0291..897646e8a8 100644 --- a/tests/models/nougat/test_tokenization_nougat.py +++ b/tests/models/nougat/test_tokenization_nougat.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/nystromformer/test_modeling_nystromformer.py b/tests/models/nystromformer/test_modeling_nystromformer.py index 73da6cec18..7966b03c0f 100644 --- a/tests/models/nystromformer/test_modeling_nystromformer.py +++ b/tests/models/nystromformer/test_modeling_nystromformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/olmo/test_modeling_olmo.py b/tests/models/olmo/test_modeling_olmo.py index fb4b10e910..ad6363ac67 100644 --- a/tests/models/olmo/test_modeling_olmo.py +++ b/tests/models/olmo/test_modeling_olmo.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/olmo2/test_modeling_olmo2.py b/tests/models/olmo2/test_modeling_olmo2.py index 222aeb5b39..455c63551b 100644 --- a/tests/models/olmo2/test_modeling_olmo2.py +++ b/tests/models/olmo2/test_modeling_olmo2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/olmoe/test_modeling_olmoe.py b/tests/models/olmoe/test_modeling_olmoe.py index 9c72225edc..e9d6bb8df8 100644 --- a/tests/models/olmoe/test_modeling_olmoe.py +++ b/tests/models/olmoe/test_modeling_olmoe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/omdet_turbo/test_modeling_omdet_turbo.py b/tests/models/omdet_turbo/test_modeling_omdet_turbo.py index e3996ade03..457572fbbe 100644 --- a/tests/models/omdet_turbo/test_modeling_omdet_turbo.py +++ b/tests/models/omdet_turbo/test_modeling_omdet_turbo.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/oneformer/test_image_processing_oneformer.py b/tests/models/oneformer/test_image_processing_oneformer.py index 7ac52f76b4..191b55698f 100644 --- a/tests/models/oneformer/test_image_processing_oneformer.py +++ b/tests/models/oneformer/test_image_processing_oneformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/oneformer/test_modeling_oneformer.py b/tests/models/oneformer/test_modeling_oneformer.py index c544154b23..446003c59d 100644 --- a/tests/models/oneformer/test_modeling_oneformer.py +++ b/tests/models/oneformer/test_modeling_oneformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/oneformer/test_processor_oneformer.py b/tests/models/oneformer/test_processor_oneformer.py index 2a9d9f859c..5e5a26e3a7 100644 --- a/tests/models/oneformer/test_processor_oneformer.py +++ b/tests/models/oneformer/test_processor_oneformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,7 +41,7 @@ if is_vision_available(): def prepare_metadata(class_info_file, repo_path="shi-labs/oneformer_demo"): - with open(hf_hub_download(repo_path, class_info_file, repo_type="dataset"), "r") as f: + with open(hf_hub_download(repo_path, class_info_file, repo_type="dataset")) as f: class_info = json.load(f) metadata = {} class_names = [] diff --git a/tests/models/openai/test_modeling_openai.py b/tests/models/openai/test_modeling_openai.py index c474855684..bba4ad8660 100644 --- a/tests/models/openai/test_modeling_openai.py +++ b/tests/models/openai/test_modeling_openai.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/openai/test_modeling_tf_openai.py b/tests/models/openai/test_modeling_tf_openai.py index 43ffe4592a..44dc5a4b63 100644 --- a/tests/models/openai/test_modeling_tf_openai.py +++ b/tests/models/openai/test_modeling_tf_openai.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/openai/test_tokenization_openai.py b/tests/models/openai/test_tokenization_openai.py index e91765f93d..b2d8d4bc7e 100644 --- a/tests/models/openai/test_tokenization_openai.py +++ b/tests/models/openai/test_tokenization_openai.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/opt/test_modeling_flax_opt.py b/tests/models/opt/test_modeling_flax_opt.py index 0b943de559..0e38ad69ea 100644 --- a/tests/models/opt/test_modeling_flax_opt.py +++ b/tests/models/opt/test_modeling_flax_opt.py @@ -155,7 +155,7 @@ class FlaxOPTModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -197,7 +197,7 @@ class FlaxOPTModelTester: outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index 6fc00d6daa..15e8968cfb 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/opt/test_modeling_tf_opt.py b/tests/models/opt/test_modeling_tf_opt.py index 39c38170e3..d36fa885c9 100644 --- a/tests/models/opt/test_modeling_tf_opt.py +++ b/tests/models/opt/test_modeling_tf_opt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/owlv2/test_image_processing_owlv2.py b/tests/models/owlv2/test_image_processing_owlv2.py index cc6cf4b833..da679c6b08 100644 --- a/tests/models/owlv2/test_image_processing_owlv2.py +++ b/tests/models/owlv2/test_image_processing_owlv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/owlv2/test_modeling_owlv2.py b/tests/models/owlv2/test_modeling_owlv2.py index 9b38fa1a9f..ff297836f3 100644 --- a/tests/models/owlv2/test_modeling_owlv2.py +++ b/tests/models/owlv2/test_modeling_owlv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/owlvit/test_image_processing_owlvit.py b/tests/models/owlvit/test_image_processing_owlvit.py index d6297de229..7d79fb2fb3 100644 --- a/tests/models/owlvit/test_image_processing_owlvit.py +++ b/tests/models/owlvit/test_image_processing_owlvit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/owlvit/test_modeling_owlvit.py b/tests/models/owlvit/test_modeling_owlvit.py index ecda5b178e..c1d9df4ea4 100644 --- a/tests/models/owlvit/test_modeling_owlvit.py +++ b/tests/models/owlvit/test_modeling_owlvit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/paligemma/test_modeling_paligemma.py b/tests/models/paligemma/test_modeling_paligemma.py index 8fa19cb411..924aaaf2af 100644 --- a/tests/models/paligemma/test_modeling_paligemma.py +++ b/tests/models/paligemma/test_modeling_paligemma.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/paligemma2/test_modeling_paligemma2.py b/tests/models/paligemma2/test_modeling_paligemma2.py index 140006d9f7..3f60ee33a4 100644 --- a/tests/models/paligemma2/test_modeling_paligemma2.py +++ b/tests/models/paligemma2/test_modeling_paligemma2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/patchtsmixer/test_modeling_patchtsmixer.py b/tests/models/patchtsmixer/test_modeling_patchtsmixer.py index 2f39b9e680..b5b92f4bee 100644 --- a/tests/models/patchtsmixer/test_modeling_patchtsmixer.py +++ b/tests/models/patchtsmixer/test_modeling_patchtsmixer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 IBM and HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +18,7 @@ import itertools import random import tempfile import unittest -from typing import Dict, List, Optional, Tuple, Union +from typing import Optional, Union import numpy as np from huggingface_hub import hf_hub_download @@ -333,10 +332,10 @@ class PatchTSMixerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.Test dict_output = tuple(attributes_.values()) def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/patchtst/test_modeling_patchtst.py b/tests/models/patchtst/test_modeling_patchtst.py index 8f48a6f904..77a2ce9add 100644 --- a/tests/models/patchtst/test_modeling_patchtst.py +++ b/tests/models/patchtst/test_modeling_patchtst.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pegasus/test_modeling_flax_pegasus.py b/tests/models/pegasus/test_modeling_flax_pegasus.py index e70770ccc1..9201bdf5d3 100644 --- a/tests/models/pegasus/test_modeling_flax_pegasus.py +++ b/tests/models/pegasus/test_modeling_flax_pegasus.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -145,7 +144,7 @@ class FlaxPegasusModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, inputs_dict): @@ -191,7 +190,7 @@ class FlaxPegasusModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/pegasus/test_modeling_pegasus.py b/tests/models/pegasus/test_modeling_pegasus.py index 83ef12be4f..d0b86d5fa5 100644 --- a/tests/models/pegasus/test_modeling_pegasus.py +++ b/tests/models/pegasus/test_modeling_pegasus.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pegasus/test_modeling_tf_pegasus.py b/tests/models/pegasus/test_modeling_tf_pegasus.py index 8b3cd19a5f..61f5fec2ef 100644 --- a/tests/models/pegasus/test_modeling_tf_pegasus.py +++ b/tests/models/pegasus/test_modeling_tf_pegasus.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pegasus_x/test_modeling_pegasus_x.py b/tests/models/pegasus_x/test_modeling_pegasus_x.py index cadacf716a..a1439ebaab 100644 --- a/tests/models/pegasus_x/test_modeling_pegasus_x.py +++ b/tests/models/pegasus_x/test_modeling_pegasus_x.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/perceiver/test_modeling_perceiver.py b/tests/models/perceiver/test_modeling_perceiver.py index 2cd4719083..34f134f3f4 100644 --- a/tests/models/perceiver/test_modeling_perceiver.py +++ b/tests/models/perceiver/test_modeling_perceiver.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +19,6 @@ import math import tempfile import unittest import warnings -from typing import Dict, List, Tuple import numpy as np from datasets import load_dataset @@ -559,10 +557,10 @@ class PerceiverModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCas dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/perceiver/test_tokenization_perceiver.py b/tests/models/perceiver/test_tokenization_perceiver.py index 16c279ae18..92227aab1f 100644 --- a/tests/models/perceiver/test_tokenization_perceiver.py +++ b/tests/models/perceiver/test_tokenization_perceiver.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +19,6 @@ import shutil import tempfile import unittest from functools import lru_cache -from typing import Tuple from transformers import AddedToken, BatchEncoding, PerceiverTokenizer from transformers.utils import cached_property, is_tf_available, is_torch_available @@ -58,7 +56,7 @@ class PerceiverTokenizationTest(TokenizerTesterMixin, unittest.TestCase): pretrained_name = pretrained_name or cls.tmpdirname return cls.tokenizer_class.from_pretrained(pretrained_name, **kwargs) - def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> Tuple[str, list]: + def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> tuple[str, list]: # XXX The default common tokenizer tests assume that every ID is decodable on its own. # This assumption is invalid for Perceiver because single bytes might not be # valid utf-8 (byte 128 for instance). diff --git a/tests/models/persimmon/test_modeling_persimmon.py b/tests/models/persimmon/test_modeling_persimmon.py index 5269f7183b..3b50cb6705 100644 --- a/tests/models/persimmon/test_modeling_persimmon.py +++ b/tests/models/persimmon/test_modeling_persimmon.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/phi/test_modeling_phi.py b/tests/models/phi/test_modeling_phi.py index 1812f2b61e..bda6cf98ec 100644 --- a/tests/models/phi/test_modeling_phi.py +++ b/tests/models/phi/test_modeling_phi.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 Microsoft and the HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/phi3/test_modeling_phi3.py b/tests/models/phi3/test_modeling_phi3.py index 200a34ff25..c2af64ffd8 100644 --- a/tests/models/phi3/test_modeling_phi3.py +++ b/tests/models/phi3/test_modeling_phi3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ """Testing suite for the PyTorch Phi-3 model.""" import unittest -from typing import List from parameterized import parameterized @@ -71,7 +69,7 @@ if is_torch_available(): ).logits @staticmethod - def generate(model: Phi3ForCausalLM, prompt_tokens: torch.LongTensor, max_seq_len: int) -> List[int]: + def generate(model: Phi3ForCausalLM, prompt_tokens: torch.LongTensor, max_seq_len: int) -> list[int]: model = Phi3MiniWithStaticCache(model, 1, max_seq_len + prompt_tokens.shape[-1]) response_tokens = [] diff --git a/tests/models/phi4_multimodal/test_modeling_phi4_multimodal.py b/tests/models/phi4_multimodal/test_modeling_phi4_multimodal.py index 3268d29ddf..e7f2ad6a37 100644 --- a/tests/models/phi4_multimodal/test_modeling_phi4_multimodal.py +++ b/tests/models/phi4_multimodal/test_modeling_phi4_multimodal.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/phimoe/test_modeling_phimoe.py b/tests/models/phimoe/test_modeling_phimoe.py index a61091522b..7f548bd2dc 100644 --- a/tests/models/phimoe/test_modeling_phimoe.py +++ b/tests/models/phimoe/test_modeling_phimoe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +15,6 @@ """Testing suite for the PyTorch PhiMoE model.""" import unittest -from typing import List from parameterized import parameterized @@ -70,7 +68,7 @@ if is_torch_available(): ).logits @staticmethod - def generate(model: PhimoeForCausalLM, prompt_tokens: torch.LongTensor, max_seq_len: int) -> List[int]: + def generate(model: PhimoeForCausalLM, prompt_tokens: torch.LongTensor, max_seq_len: int) -> list[int]: model = PhimoeMiniWithStaticCache(model, 1, max_seq_len + prompt_tokens.shape[-1]) response_tokens = [] diff --git a/tests/models/phobert/test_tokenization_phobert.py b/tests/models/phobert/test_tokenization_phobert.py index 323355e3ca..5936192c39 100644 --- a/tests/models/phobert/test_tokenization_phobert.py +++ b/tests/models/phobert/test_tokenization_phobert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Salesforce and HuggingFace Inc. team. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/pix2struct/test_image_processing_pix2struct.py b/tests/models/pix2struct/test_image_processing_pix2struct.py index 2650b3503b..61d360b400 100644 --- a/tests/models/pix2struct/test_image_processing_pix2struct.py +++ b/tests/models/pix2struct/test_image_processing_pix2struct.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pix2struct/test_modeling_pix2struct.py b/tests/models/pix2struct/test_modeling_pix2struct.py index 1517ae9dbd..1c1fda13f3 100644 --- a/tests/models/pix2struct/test_modeling_pix2struct.py +++ b/tests/models/pix2struct/test_modeling_pix2struct.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pixtral/test_image_processing_pixtral.py b/tests/models/pixtral/test_image_processing_pixtral.py index 3f9deded6d..ad44f162c0 100644 --- a/tests/models/pixtral/test_image_processing_pixtral.py +++ b/tests/models/pixtral/test_image_processing_pixtral.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pixtral/test_modeling_pixtral.py b/tests/models/pixtral/test_modeling_pixtral.py index 6ea6fa33c8..de3f5efc2e 100644 --- a/tests/models/pixtral/test_modeling_pixtral.py +++ b/tests/models/pixtral/test_modeling_pixtral.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/plbart/test_modeling_plbart.py b/tests/models/plbart/test_modeling_plbart.py index fec49c5559..7255f2b7c5 100644 --- a/tests/models/plbart/test_modeling_plbart.py +++ b/tests/models/plbart/test_modeling_plbart.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/poolformer/test_image_processing_poolformer.py b/tests/models/poolformer/test_image_processing_poolformer.py index 047cd23d36..e5e64d2570 100644 --- a/tests/models/poolformer/test_image_processing_poolformer.py +++ b/tests/models/poolformer/test_image_processing_poolformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/poolformer/test_modeling_poolformer.py b/tests/models/poolformer/test_modeling_poolformer.py index 6f4ead91a2..0fee2b295f 100644 --- a/tests/models/poolformer/test_modeling_poolformer.py +++ b/tests/models/poolformer/test_modeling_poolformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pop2piano/test_feature_extraction_pop2piano.py b/tests/models/pop2piano/test_feature_extraction_pop2piano.py index 2a1a767c2c..5684cbf6f5 100644 --- a/tests/models/pop2piano/test_feature_extraction_pop2piano.py +++ b/tests/models/pop2piano/test_feature_extraction_pop2piano.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pop2piano/test_modeling_pop2piano.py b/tests/models/pop2piano/test_modeling_pop2piano.py index baa79e729d..5061c73ec7 100644 --- a/tests/models/pop2piano/test_modeling_pop2piano.py +++ b/tests/models/pop2piano/test_modeling_pop2piano.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pop2piano/test_tokenization_pop2piano.py b/tests/models/pop2piano/test_tokenization_pop2piano.py index 6ee6721d81..a023421cd6 100644 --- a/tests/models/pop2piano/test_tokenization_pop2piano.py +++ b/tests/models/pop2piano/test_tokenization_pop2piano.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/prompt_depth_anything/test_image_processing_prompt_depth_anything.py b/tests/models/prompt_depth_anything/test_image_processing_prompt_depth_anything.py index 7becbe5dfa..eb40058dee 100644 --- a/tests/models/prompt_depth_anything/test_image_processing_prompt_depth_anything.py +++ b/tests/models/prompt_depth_anything/test_image_processing_prompt_depth_anything.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py b/tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py index 0dc6838a9d..23e5e9f8f3 100644 --- a/tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py +++ b/tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/prophetnet/test_modeling_prophetnet.py b/tests/models/prophetnet/test_modeling_prophetnet.py index 2687cd67f7..d6eead97cb 100644 --- a/tests/models/prophetnet/test_modeling_prophetnet.py +++ b/tests/models/prophetnet/test_modeling_prophetnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team, The Microsoft Research team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/prophetnet/test_tokenization_prophetnet.py b/tests/models/prophetnet/test_tokenization_prophetnet.py index b271c898da..0fcdcba134 100644 --- a/tests/models/prophetnet/test_tokenization_prophetnet.py +++ b/tests/models/prophetnet/test_tokenization_prophetnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team, The Microsoft Research team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pvt/test_image_processing_pvt.py b/tests/models/pvt/test_image_processing_pvt.py index de093307ab..a04ce7d025 100644 --- a/tests/models/pvt/test_image_processing_pvt.py +++ b/tests/models/pvt/test_image_processing_pvt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pvt/test_modeling_pvt.py b/tests/models/pvt/test_modeling_pvt.py index ea5a1b69d9..d52348555a 100644 --- a/tests/models/pvt/test_modeling_pvt.py +++ b/tests/models/pvt/test_modeling_pvt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/pvt_v2/test_modeling_pvt_v2.py b/tests/models/pvt_v2/test_modeling_pvt_v2.py index 381ab1c000..d1a765b19d 100644 --- a/tests/models/pvt_v2/test_modeling_pvt_v2.py +++ b/tests/models/pvt_v2/test_modeling_pvt_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2/test_modeling_qwen2.py b/tests/models/qwen2/test_modeling_qwen2.py index 943fa3a91b..d9fc25efc3 100644 --- a/tests/models/qwen2/test_modeling_qwen2.py +++ b/tests/models/qwen2/test_modeling_qwen2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2/test_tokenization_qwen2.py b/tests/models/qwen2/test_tokenization_qwen2.py index e37ecac969..a687cd4b92 100644 --- a/tests/models/qwen2/test_tokenization_qwen2.py +++ b/tests/models/qwen2/test_tokenization_qwen2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2_5_vl/test_modeling_qwen2_5_vl.py b/tests/models/qwen2_5_vl/test_modeling_qwen2_5_vl.py index 5bbd21d6e9..82e8229f79 100644 --- a/tests/models/qwen2_5_vl/test_modeling_qwen2_5_vl.py +++ b/tests/models/qwen2_5_vl/test_modeling_qwen2_5_vl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2_audio/test_modeling_qwen2_audio.py b/tests/models/qwen2_audio/test_modeling_qwen2_audio.py index e4b16d8344..3d2e2c7d37 100644 --- a/tests/models/qwen2_audio/test_modeling_qwen2_audio.py +++ b/tests/models/qwen2_audio/test_modeling_qwen2_audio.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2_moe/test_modeling_qwen2_moe.py b/tests/models/qwen2_moe/test_modeling_qwen2_moe.py index b7b8fbab11..b89382867e 100644 --- a/tests/models/qwen2_moe/test_modeling_qwen2_moe.py +++ b/tests/models/qwen2_moe/test_modeling_qwen2_moe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py b/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py index 95d758f438..7f352b2f3a 100644 --- a/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py +++ b/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen2_vl/test_modeling_qwen2_vl.py b/tests/models/qwen2_vl/test_modeling_qwen2_vl.py index 13c58fae74..8c9086f162 100644 --- a/tests/models/qwen2_vl/test_modeling_qwen2_vl.py +++ b/tests/models/qwen2_vl/test_modeling_qwen2_vl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen3/test_modeling_qwen3.py b/tests/models/qwen3/test_modeling_qwen3.py index bd46f11ce3..917713a217 100644 --- a/tests/models/qwen3/test_modeling_qwen3.py +++ b/tests/models/qwen3/test_modeling_qwen3.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/qwen3_moe/test_modeling_qwen3_moe.py b/tests/models/qwen3_moe/test_modeling_qwen3_moe.py index e548d14ba7..b192afae1e 100644 --- a/tests/models/qwen3_moe/test_modeling_qwen3_moe.py +++ b/tests/models/qwen3_moe/test_modeling_qwen3_moe.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/rag/test_modeling_rag.py b/tests/models/rag/test_modeling_rag.py index 35c14b64c6..7fce4ca392 100644 --- a/tests/models/rag/test_modeling_rag.py +++ b/tests/models/rag/test_modeling_rag.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020, The RAG Authors and The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/recurrent_gemma/test_modeling_recurrent_gemma.py b/tests/models/recurrent_gemma/test_modeling_recurrent_gemma.py index 36ccd04cf6..b15bf26e06 100644 --- a/tests/models/recurrent_gemma/test_modeling_recurrent_gemma.py +++ b/tests/models/recurrent_gemma/test_modeling_recurrent_gemma.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/reformer/test_modeling_reformer.py b/tests/models/reformer/test_modeling_reformer.py index b4e493dd2c..3937edc0e3 100644 --- a/tests/models/reformer/test_modeling_reformer.py +++ b/tests/models/reformer/test_modeling_reformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 Huggingface # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/models/regnet/test_modeling_flax_regnet.py b/tests/models/regnet/test_modeling_flax_regnet.py index 30511c84c7..f7158efdfe 100644 --- a/tests/models/regnet/test_modeling_flax_regnet.py +++ b/tests/models/regnet/test_modeling_flax_regnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/regnet/test_modeling_regnet.py b/tests/models/regnet/test_modeling_regnet.py index 62faeb58b2..9f88bc8c9c 100644 --- a/tests/models/regnet/test_modeling_regnet.py +++ b/tests/models/regnet/test_modeling_regnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/regnet/test_modeling_tf_regnet.py b/tests/models/regnet/test_modeling_tf_regnet.py index b2998ae070..df017fb416 100644 --- a/tests/models/regnet/test_modeling_tf_regnet.py +++ b/tests/models/regnet/test_modeling_tf_regnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ from __future__ import annotations import inspect import unittest -from typing import List, Tuple from transformers import RegNetConfig from transformers.testing_utils import require_tf, require_vision, slow @@ -211,7 +209,7 @@ class TFRegNetModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCa dict_output = model(dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: diff --git a/tests/models/rembert/test_modeling_rembert.py b/tests/models/rembert/test_modeling_rembert.py index 956f1a2b80..66eeab1018 100644 --- a/tests/models/rembert/test_modeling_rembert.py +++ b/tests/models/rembert/test_modeling_rembert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/rembert/test_modeling_tf_rembert.py b/tests/models/rembert/test_modeling_tf_rembert.py index 8698d3febc..551b4fcc61 100644 --- a/tests/models/rembert/test_modeling_tf_rembert.py +++ b/tests/models/rembert/test_modeling_tf_rembert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/rembert/test_tokenization_rembert.py b/tests/models/rembert/test_tokenization_rembert.py index c2ee3619f8..ffebaed315 100644 --- a/tests/models/rembert/test_tokenization_rembert.py +++ b/tests/models/rembert/test_tokenization_rembert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/resnet/test_modeling_resnet.py b/tests/models/resnet/test_modeling_resnet.py index d8790130df..e63d617c0e 100644 --- a/tests/models/resnet/test_modeling_resnet.py +++ b/tests/models/resnet/test_modeling_resnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/resnet/test_modeling_tf_resnet.py b/tests/models/resnet/test_modeling_tf_resnet.py index f5762c7225..a64a3479ed 100644 --- a/tests/models/resnet/test_modeling_tf_resnet.py +++ b/tests/models/resnet/test_modeling_tf_resnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roberta/test_modeling_roberta.py b/tests/models/roberta/test_modeling_roberta.py index 5d688075a8..d92cfbbb13 100644 --- a/tests/models/roberta/test_modeling_roberta.py +++ b/tests/models/roberta/test_modeling_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roberta/test_modeling_tf_roberta.py b/tests/models/roberta/test_modeling_tf_roberta.py index 8125a7f0a0..0ee5cd03a7 100644 --- a/tests/models/roberta/test_modeling_tf_roberta.py +++ b/tests/models/roberta/test_modeling_tf_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roberta/test_tokenization_roberta.py b/tests/models/roberta/test_tokenization_roberta.py index e2760f646c..22b93e3ffb 100644 --- a/tests/models/roberta/test_tokenization_roberta.py +++ b/tests/models/roberta/test_tokenization_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -138,7 +137,7 @@ class RobertaTokenizationTest(TokenizerTesterMixin, unittest.TestCase): tokenizer = self.get_tokenizer() sequence = "Encode this sequence." - space_encoding = tokenizer.byte_encoder[" ".encode("utf-8")[0]] + space_encoding = tokenizer.byte_encoder[b" "[0]] # Testing encoder arguments encoded = tokenizer.encode(sequence, add_special_tokens=False, add_prefix_space=False) diff --git a/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py b/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py index 11fbf6de35..4de4679596 100644 --- a/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py +++ b/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py b/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py index 2138541603..48dc45fca4 100644 --- a/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py +++ b/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roc_bert/test_modeling_roc_bert.py b/tests/models/roc_bert/test_modeling_roc_bert.py index 95de5613a2..4f25106873 100644 --- a/tests/models/roc_bert/test_modeling_roc_bert.py +++ b/tests/models/roc_bert/test_modeling_roc_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roc_bert/test_tokenization_roc_bert.py b/tests/models/roc_bert/test_tokenization_roc_bert.py index 885975b8df..11083e614a 100644 --- a/tests/models/roc_bert/test_tokenization_roc_bert.py +++ b/tests/models/roc_bert/test_tokenization_roc_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roformer/test_modeling_roformer.py b/tests/models/roformer/test_modeling_roformer.py index 22c1e8af8a..7dca92ddf4 100644 --- a/tests/models/roformer/test_modeling_roformer.py +++ b/tests/models/roformer/test_modeling_roformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roformer/test_modeling_tf_roformer.py b/tests/models/roformer/test_modeling_tf_roformer.py index 8e10a092af..c379672430 100644 --- a/tests/models/roformer/test_modeling_tf_roformer.py +++ b/tests/models/roformer/test_modeling_tf_roformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/roformer/test_tokenization_roformer.py b/tests/models/roformer/test_tokenization_roformer.py index e6db4f0d09..f092458a18 100644 --- a/tests/models/roformer/test_tokenization_roformer.py +++ b/tests/models/roformer/test_tokenization_roformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/rt_detr/test_image_processing_rt_detr.py b/tests/models/rt_detr/test_image_processing_rt_detr.py index 41e26e2a13..6f8fad4f9c 100644 --- a/tests/models/rt_detr/test_image_processing_rt_detr.py +++ b/tests/models/rt_detr/test_image_processing_rt_detr.py @@ -125,7 +125,7 @@ class RtDetrImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase): def test_valid_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) params = {"image_id": 39769, "annotations": target} @@ -162,7 +162,7 @@ class RtDetrImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase): def test_call_pytorch_with_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -268,7 +268,7 @@ class RtDetrImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase): image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) annotations_0 = {"image_id": 39769, "annotations": target} @@ -385,7 +385,7 @@ class RtDetrImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase): def test_fast_processor_equivalence_cpu_gpu_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} diff --git a/tests/models/rt_detr/test_modeling_rt_detr_resnet.py b/tests/models/rt_detr/test_modeling_rt_detr_resnet.py index d7bfadceca..934ead651f 100644 --- a/tests/models/rt_detr/test_modeling_rt_detr_resnet.py +++ b/tests/models/rt_detr/test_modeling_rt_detr_resnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/rwkv/test_modeling_rwkv.py b/tests/models/rwkv/test_modeling_rwkv.py index 7915be09eb..aad32b1be8 100644 --- a/tests/models/rwkv/test_modeling_rwkv.py +++ b/tests/models/rwkv/test_modeling_rwkv.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -252,7 +251,7 @@ class RwkvModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin is_inside_interval = (min_value >= expected_min) and (max_value <= expected_max) if not is_inside_interval: - standardMsg = "%s not found in %s" % (safe_repr(member), safe_repr(container)) + standardMsg = f"{safe_repr(member)} not found in {safe_repr(container)}" self.fail(self._formatMessage(msg, standardMsg)) def test_config(self): diff --git a/tests/models/sam/test_modeling_sam.py b/tests/models/sam/test_modeling_sam.py index 2a17fad334..38a2529730 100644 --- a/tests/models/sam/test_modeling_sam.py +++ b/tests/models/sam/test_modeling_sam.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/sam/test_modeling_tf_sam.py b/tests/models/sam/test_modeling_tf_sam.py index 305f429ea0..01c3ca0588 100644 --- a/tests/models/sam/test_modeling_tf_sam.py +++ b/tests/models/sam/test_modeling_tf_sam.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/seamless_m4t/test_feature_extraction_seamless_m4t.py b/tests/models/seamless_m4t/test_feature_extraction_seamless_m4t.py index f5e59e49fc..2b99bbf95b 100644 --- a/tests/models/seamless_m4t/test_feature_extraction_seamless_m4t.py +++ b/tests/models/seamless_m4t/test_feature_extraction_seamless_m4t.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/seamless_m4t/test_modeling_seamless_m4t.py b/tests/models/seamless_m4t/test_modeling_seamless_m4t.py index d7f0158044..938bdcf619 100644 --- a/tests/models/seamless_m4t/test_modeling_seamless_m4t.py +++ b/tests/models/seamless_m4t/test_modeling_seamless_m4t.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/seamless_m4t_v2/test_modeling_seamless_m4t_v2.py b/tests/models/seamless_m4t_v2/test_modeling_seamless_m4t_v2.py index 2342f5502c..6dc61db6f6 100644 --- a/tests/models/seamless_m4t_v2/test_modeling_seamless_m4t_v2.py +++ b/tests/models/seamless_m4t_v2/test_modeling_seamless_m4t_v2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/segformer/test_image_processing_segformer.py b/tests/models/segformer/test_image_processing_segformer.py index dba2de7e48..5b1b84bd00 100644 --- a/tests/models/segformer/test_image_processing_segformer.py +++ b/tests/models/segformer/test_image_processing_segformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/segformer/test_modeling_segformer.py b/tests/models/segformer/test_modeling_segformer.py index 30ea5c63f4..71aa8b1386 100644 --- a/tests/models/segformer/test_modeling_segformer.py +++ b/tests/models/segformer/test_modeling_segformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/segformer/test_modeling_tf_segformer.py b/tests/models/segformer/test_modeling_tf_segformer.py index 384754ecbe..8e61e3e001 100644 --- a/tests/models/segformer/test_modeling_tf_segformer.py +++ b/tests/models/segformer/test_modeling_tf_segformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ from __future__ import annotations import inspect import unittest -from typing import List, Tuple from transformers import SegformerConfig from transformers.file_utils import is_tf_available, is_vision_available @@ -147,7 +145,7 @@ class TFSegformerModelTester: if for_segmentation: inputs_dict = {"pixel_values": pixel_values, "labels": seg_labels} else: - inputs_dict = {"pixel_values": pixel_values, "labels": tf.zeros((self.batch_size))} + inputs_dict = {"pixel_values": pixel_values, "labels": tf.zeros(self.batch_size)} return config, inputs_dict @@ -298,7 +296,7 @@ class TFSegformerModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.Tes dict_output = model(dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: diff --git a/tests/models/seggpt/test_image_processing_seggpt.py b/tests/models/seggpt/test_image_processing_seggpt.py index 5c58f4846b..3108cfb5e8 100644 --- a/tests/models/seggpt/test_image_processing_seggpt.py +++ b/tests/models/seggpt/test_image_processing_seggpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/seggpt/test_modeling_seggpt.py b/tests/models/seggpt/test_modeling_seggpt.py index 3a31557971..1176613fa2 100644 --- a/tests/models/seggpt/test_modeling_seggpt.py +++ b/tests/models/seggpt/test_modeling_seggpt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/sew/test_modeling_sew.py b/tests/models/sew/test_modeling_sew.py index 76b0dc2a45..9a7430c641 100644 --- a/tests/models/sew/test_modeling_sew.py +++ b/tests/models/sew/test_modeling_sew.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/sew_d/test_modeling_sew_d.py b/tests/models/sew_d/test_modeling_sew_d.py index c6b28b2474..21daf29006 100644 --- a/tests/models/sew_d/test_modeling_sew_d.py +++ b/tests/models/sew_d/test_modeling_sew_d.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/shieldgemma2/test_modeling_shieldgemma2.py b/tests/models/shieldgemma2/test_modeling_shieldgemma2.py index fdc5d9e713..f46a2d229e 100644 --- a/tests/models/shieldgemma2/test_modeling_shieldgemma2.py +++ b/tests/models/shieldgemma2/test_modeling_shieldgemma2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/siglip/test_image_processing_siglip.py b/tests/models/siglip/test_image_processing_siglip.py index b853f06bfe..4dbe16fab6 100644 --- a/tests/models/siglip/test_image_processing_siglip.py +++ b/tests/models/siglip/test_image_processing_siglip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/siglip/test_modeling_siglip.py b/tests/models/siglip/test_modeling_siglip.py index 10d57a5aeb..419bb3efa5 100644 --- a/tests/models/siglip/test_modeling_siglip.py +++ b/tests/models/siglip/test_modeling_siglip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/siglip/test_tokenization_siglip.py b/tests/models/siglip/test_tokenization_siglip.py index f4bc56c5e3..f9b60101c8 100644 --- a/tests/models/siglip/test_tokenization_siglip.py +++ b/tests/models/siglip/test_tokenization_siglip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/siglip2/test_image_processing_siglip2.py b/tests/models/siglip2/test_image_processing_siglip2.py index dd96db9c56..a8edb642fa 100644 --- a/tests/models/siglip2/test_image_processing_siglip2.py +++ b/tests/models/siglip2/test_image_processing_siglip2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/siglip2/test_modeling_siglip2.py b/tests/models/siglip2/test_modeling_siglip2.py index 885f57751b..5c714205f7 100644 --- a/tests/models/siglip2/test_modeling_siglip2.py +++ b/tests/models/siglip2/test_modeling_siglip2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/smolvlm/test_image_processing_smolvlm.py b/tests/models/smolvlm/test_image_processing_smolvlm.py index 273a4c0c3c..f652186862 100644 --- a/tests/models/smolvlm/test_image_processing_smolvlm.py +++ b/tests/models/smolvlm/test_image_processing_smolvlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/smolvlm/test_modeling_smolvlm.py b/tests/models/smolvlm/test_modeling_smolvlm.py index e506d68809..8e2839166b 100644 --- a/tests/models/smolvlm/test_modeling_smolvlm.py +++ b/tests/models/smolvlm/test_modeling_smolvlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/smolvlm/test_processor_smolvlm.py b/tests/models/smolvlm/test_processor_smolvlm.py index d276d92a50..ed53c33331 100644 --- a/tests/models/smolvlm/test_processor_smolvlm.py +++ b/tests/models/smolvlm/test_processor_smolvlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py b/tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py index 5348315c7c..649ac3e292 100644 --- a/tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py +++ b/tests/models/speech_encoder_decoder/test_modeling_flax_speech_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -433,7 +432,7 @@ class FlaxEncoderDecoderMixin: self.check_encoder_decoder_model_generate(**input_ids_dict) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") @slow diff --git a/tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py b/tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py index 399a111530..b7c3b97e5c 100644 --- a/tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py +++ b/tests/models/speech_encoder_decoder/test_modeling_speech_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py b/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py index 8b10b88650..49433e1156 100644 --- a/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py +++ b/tests/models/speech_to_text/test_feature_extraction_speech_to_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speech_to_text/test_modeling_speech_to_text.py b/tests/models/speech_to_text/test_modeling_speech_to_text.py index bcd76a87e9..3b0d03a3fb 100644 --- a/tests/models/speech_to_text/test_modeling_speech_to_text.py +++ b/tests/models/speech_to_text/test_modeling_speech_to_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py b/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py index 1c80e666d0..6073afc2bd 100644 --- a/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py +++ b/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speecht5/test_feature_extraction_speecht5.py b/tests/models/speecht5/test_feature_extraction_speecht5.py index 9b3f539476..c886704a04 100644 --- a/tests/models/speecht5/test_feature_extraction_speecht5.py +++ b/tests/models/speecht5/test_feature_extraction_speecht5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021-2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speecht5/test_modeling_speecht5.py b/tests/models/speecht5/test_modeling_speecht5.py index 3b7ae7fa04..dcff134ef8 100644 --- a/tests/models/speecht5/test_modeling_speecht5.py +++ b/tests/models/speecht5/test_modeling_speecht5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/speecht5/test_tokenization_speecht5.py b/tests/models/speecht5/test_tokenization_speecht5.py index 026fd1d2f4..76554b0ebd 100644 --- a/tests/models/speecht5/test_tokenization_speecht5.py +++ b/tests/models/speecht5/test_tokenization_speecht5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/splinter/test_modeling_splinter.py b/tests/models/splinter/test_modeling_splinter.py index 4b730017d9..795adb86b3 100644 --- a/tests/models/splinter/test_modeling_splinter.py +++ b/tests/models/splinter/test_modeling_splinter.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/splinter/test_tokenization_splinter.py b/tests/models/splinter/test_tokenization_splinter.py index f654e2e5b7..1b12db34f8 100644 --- a/tests/models/splinter/test_tokenization_splinter.py +++ b/tests/models/splinter/test_tokenization_splinter.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/squeezebert/test_modeling_squeezebert.py b/tests/models/squeezebert/test_modeling_squeezebert.py index 15b849722b..8da8626d7d 100644 --- a/tests/models/squeezebert/test_modeling_squeezebert.py +++ b/tests/models/squeezebert/test_modeling_squeezebert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The SqueezeBert authors and The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/squeezebert/test_tokenization_squeezebert.py b/tests/models/squeezebert/test_tokenization_squeezebert.py index 0a75e768cc..eb75dc423a 100644 --- a/tests/models/squeezebert/test_tokenization_squeezebert.py +++ b/tests/models/squeezebert/test_tokenization_squeezebert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The SqueezeBert authors and The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/stablelm/test_modeling_stablelm.py b/tests/models/stablelm/test_modeling_stablelm.py index 5cc21b8e3d..a984d908ea 100644 --- a/tests/models/stablelm/test_modeling_stablelm.py +++ b/tests/models/stablelm/test_modeling_stablelm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/starcoder2/test_modeling_starcoder2.py b/tests/models/starcoder2/test_modeling_starcoder2.py index e27b930322..7c98425cfb 100644 --- a/tests/models/starcoder2/test_modeling_starcoder2.py +++ b/tests/models/starcoder2/test_modeling_starcoder2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 BigCode and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/superglue/test_modeling_superglue.py b/tests/models/superglue/test_modeling_superglue.py index 1d6ccc59d6..84fbb6c4bf 100644 --- a/tests/models/superglue/test_modeling_superglue.py +++ b/tests/models/superglue/test_modeling_superglue.py @@ -13,7 +13,6 @@ # limitations under the License. import inspect import unittest -from typing import List from datasets import load_dataset @@ -43,8 +42,8 @@ class SuperGlueModelTester: image_height=60, keypoint_detector_config=None, hidden_size: int = 64, - keypoint_encoder_sizes: List[int] = [32, 64], - gnn_layers_types: List[str] = ["self", "cross"] * 2, + keypoint_encoder_sizes: list[int] = [32, 64], + gnn_layers_types: list[str] = ["self", "cross"] * 2, num_attention_heads: int = 4, sinkhorn_iterations: int = 100, matching_threshold: float = 0.2, diff --git a/tests/models/superpoint/test_modeling_superpoint.py b/tests/models/superpoint/test_modeling_superpoint.py index 6fe2df0002..329148e67e 100644 --- a/tests/models/superpoint/test_modeling_superpoint.py +++ b/tests/models/superpoint/test_modeling_superpoint.py @@ -13,7 +13,6 @@ # limitations under the License. import inspect import unittest -from typing import List from transformers.models.superpoint.configuration_superpoint import SuperPointConfig from transformers.testing_utils import is_flaky, require_torch, require_vision, slow, torch_device @@ -43,7 +42,7 @@ class SuperPointModelTester: batch_size=3, image_width=80, image_height=60, - encoder_hidden_sizes: List[int] = [32, 32, 64, 64], + encoder_hidden_sizes: list[int] = [32, 32, 64, 64], decoder_hidden_size: int = 128, keypoint_decoder_dim: int = 65, descriptor_decoder_dim: int = 128, diff --git a/tests/models/swiftformer/test_modeling_swiftformer.py b/tests/models/swiftformer/test_modeling_swiftformer.py index 0d6f471e96..35b678952d 100644 --- a/tests/models/swiftformer/test_modeling_swiftformer.py +++ b/tests/models/swiftformer/test_modeling_swiftformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/swiftformer/test_modeling_tf_swiftformer.py b/tests/models/swiftformer/test_modeling_tf_swiftformer.py index b05e390597..161e5db753 100644 --- a/tests/models/swiftformer/test_modeling_tf_swiftformer.py +++ b/tests/models/swiftformer/test_modeling_tf_swiftformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/swin/test_modeling_swin.py b/tests/models/swin/test_modeling_swin.py index cf33a3f3df..a211fa97db 100644 --- a/tests/models/swin/test_modeling_swin.py +++ b/tests/models/swin/test_modeling_swin.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/swin/test_modeling_tf_swin.py b/tests/models/swin/test_modeling_tf_swin.py index 6a443571d3..b72369480d 100644 --- a/tests/models/swin/test_modeling_tf_swin.py +++ b/tests/models/swin/test_modeling_tf_swin.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/swin2sr/test_image_processing_swin2sr.py b/tests/models/swin2sr/test_image_processing_swin2sr.py index 4467a83444..ec69d7f35b 100644 --- a/tests/models/swin2sr/test_image_processing_swin2sr.py +++ b/tests/models/swin2sr/test_image_processing_swin2sr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/swin2sr/test_modeling_swin2sr.py b/tests/models/swin2sr/test_modeling_swin2sr.py index 5310835e98..30a0c3de9a 100644 --- a/tests/models/swin2sr/test_modeling_swin2sr.py +++ b/tests/models/swin2sr/test_modeling_swin2sr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/swinv2/test_modeling_swinv2.py b/tests/models/swinv2/test_modeling_swinv2.py index a4e93eeb3d..1324df2947 100644 --- a/tests/models/swinv2/test_modeling_swinv2.py +++ b/tests/models/swinv2/test_modeling_swinv2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/switch_transformers/test_modeling_switch_transformers.py b/tests/models/switch_transformers/test_modeling_switch_transformers.py index 622c579843..0af2f32549 100644 --- a/tests/models/switch_transformers/test_modeling_switch_transformers.py +++ b/tests/models/switch_transformers/test_modeling_switch_transformers.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 Google SwitchTransformers Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/t5/test_modeling_flax_t5.py b/tests/models/t5/test_modeling_flax_t5.py index 703b9973cb..d0eb9e0f50 100644 --- a/tests/models/t5/test_modeling_flax_t5.py +++ b/tests/models/t5/test_modeling_flax_t5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 Google T5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -195,7 +194,7 @@ class FlaxT5ModelTester: outputs = model.decode(decoder_input_ids, encoder_outputs, decoder_attention_mask=decoder_attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def prepare_config_and_inputs_for_common(self): diff --git a/tests/models/t5/test_modeling_t5.py b/tests/models/t5/test_modeling_t5.py index ce543e6066..4a2bb0232c 100644 --- a/tests/models/t5/test_modeling_t5.py +++ b/tests/models/t5/test_modeling_t5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Google T5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/t5/test_modeling_tf_t5.py b/tests/models/t5/test_modeling_tf_t5.py index 7e6367582e..8dd06d6e25 100644 --- a/tests/models/t5/test_modeling_tf_t5.py +++ b/tests/models/t5/test_modeling_tf_t5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Google T5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/t5/test_tokenization_t5.py b/tests/models/t5/test_tokenization_t5.py index aba5dde8cb..b6f8478a04 100644 --- a/tests/models/t5/test_tokenization_t5.py +++ b/tests/models/t5/test_tokenization_t5.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 Google T5 Authors and HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/table_transformer/test_modeling_table_transformer.py b/tests/models/table_transformer/test_modeling_table_transformer.py index 9995aae7d4..6d35c73e3d 100644 --- a/tests/models/table_transformer/test_modeling_table_transformer.py +++ b/tests/models/table_transformer/test_modeling_table_transformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/tapas/test_modeling_tapas.py b/tests/models/tapas/test_modeling_tapas.py index c6f880b86d..a21981ce49 100644 --- a/tests/models/tapas/test_modeling_tapas.py +++ b/tests/models/tapas/test_modeling_tapas.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/tapas/test_modeling_tf_tapas.py b/tests/models/tapas/test_modeling_tf_tapas.py index 11915b98bb..ab00f70673 100644 --- a/tests/models/tapas/test_modeling_tf_tapas.py +++ b/tests/models/tapas/test_modeling_tf_tapas.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/tapas/test_tokenization_tapas.py b/tests/models/tapas/test_tokenization_tapas.py index f50e9eb867..103e8428d6 100644 --- a/tests/models/tapas/test_tokenization_tapas.py +++ b/tests/models/tapas/test_tokenization_tapas.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,6 @@ import os import shutil import tempfile import unittest -from typing import List import numpy as np import pandas as pd @@ -403,7 +401,7 @@ class TapasTokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertEqual([e[0] for e in expected_results], tokens["offset_mapping"]) def test_add_special_tokens(self): - tokenizers: List[TapasTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[TapasTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): input_table = self.get_table(tokenizer, length=0) @@ -418,7 +416,7 @@ class TapasTokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertTrue(special_token not in decoded) def test_add_tokens_tokenizer(self): - tokenizers: List[TapasTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[TapasTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): table = self.get_table(tokenizer, length=0) diff --git a/tests/models/textnet/test_image_processing_textnet.py b/tests/models/textnet/test_image_processing_textnet.py index 7765397802..b5064dab47 100644 --- a/tests/models/textnet/test_image_processing_textnet.py +++ b/tests/models/textnet/test_image_processing_textnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/textnet/test_modeling_textnet.py b/tests/models/textnet/test_modeling_textnet.py index 1c88c95cc8..bf91b36039 100644 --- a/tests/models/textnet/test_modeling_textnet.py +++ b/tests/models/textnet/test_modeling_textnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 the Fast authors and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/time_series_transformer/test_modeling_time_series_transformer.py b/tests/models/time_series_transformer/test_modeling_time_series_transformer.py index f9dfefe376..dab8bb6c91 100644 --- a/tests/models/time_series_transformer/test_modeling_time_series_transformer.py +++ b/tests/models/time_series_transformer/test_modeling_time_series_transformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/timesformer/test_modeling_timesformer.py b/tests/models/timesformer/test_modeling_timesformer.py index 2cbe3a6dce..247d0a5fba 100644 --- a/tests/models/timesformer/test_modeling_timesformer.py +++ b/tests/models/timesformer/test_modeling_timesformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/timm_backbone/test_modeling_timm_backbone.py b/tests/models/timm_backbone/test_modeling_timm_backbone.py index 06e9aebb99..af48bc76dc 100644 --- a/tests/models/timm_backbone/test_modeling_timm_backbone.py +++ b/tests/models/timm_backbone/test_modeling_timm_backbone.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/timm_wrapper/test_image_processing_timm_wrapper.py b/tests/models/timm_wrapper/test_image_processing_timm_wrapper.py index 49d864178d..3bdb557d55 100644 --- a/tests/models/timm_wrapper/test_image_processing_timm_wrapper.py +++ b/tests/models/timm_wrapper/test_image_processing_timm_wrapper.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/timm_wrapper/test_modeling_timm_wrapper.py b/tests/models/timm_wrapper/test_modeling_timm_wrapper.py index 2628106512..821ade8dbc 100644 --- a/tests/models/timm_wrapper/test_modeling_timm_wrapper.py +++ b/tests/models/timm_wrapper/test_modeling_timm_wrapper.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/trocr/test_modeling_trocr.py b/tests/models/trocr/test_modeling_trocr.py index 9af22b1d1b..a33af62371 100644 --- a/tests/models/trocr/test_modeling_trocr.py +++ b/tests/models/trocr/test_modeling_trocr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/tvp/test_image_processing_tvp.py b/tests/models/tvp/test_image_processing_tvp.py index 99ddcc51b4..6183c2e163 100644 --- a/tests/models/tvp/test_image_processing_tvp.py +++ b/tests/models/tvp/test_image_processing_tvp.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The Intel Team Authors, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,7 @@ import unittest -from typing import Dict, List, Optional, Union +from typing import Optional, Union import numpy as np @@ -40,18 +39,18 @@ class TvpImageProcessingTester: self, parent, do_resize: bool = True, - size: Dict[str, int] = {"longest_edge": 40}, + size: dict[str, int] = {"longest_edge": 40}, do_center_crop: bool = False, - crop_size: Dict[str, int] = None, + crop_size: dict[str, int] = None, do_rescale: bool = False, rescale_factor: Union[int, float] = 1 / 255, do_pad: bool = True, - pad_size: Dict[str, int] = {"height": 80, "width": 80}, + pad_size: dict[str, int] = {"height": 80, "width": 80}, fill: int = None, pad_mode: PaddingMode = None, do_normalize: bool = True, - image_mean: Optional[Union[float, List[float]]] = [0.48145466, 0.4578275, 0.40821073], - image_std: Optional[Union[float, List[float]]] = [0.26862954, 0.26130258, 0.27577711], + image_mean: Optional[Union[float, list[float]]] = [0.48145466, 0.4578275, 0.40821073], + image_std: Optional[Union[float, list[float]]] = [0.26862954, 0.26130258, 0.27577711], batch_size=2, min_resolution=40, max_resolution=80, diff --git a/tests/models/tvp/test_modeling_tvp.py b/tests/models/tvp/test_modeling_tvp.py index 3ac01c53d5..5c4e3d7de4 100644 --- a/tests/models/tvp/test_modeling_tvp.py +++ b/tests/models/tvp/test_modeling_tvp.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The Intel Team Authors, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/udop/test_modeling_udop.py b/tests/models/udop/test_modeling_udop.py index c5f485d797..3e86c169bf 100644 --- a/tests/models/udop/test_modeling_udop.py +++ b/tests/models/udop/test_modeling_udop.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/udop/test_processor_udop.py b/tests/models/udop/test_processor_udop.py index 621b761b5f..8bf41d7ddc 100644 --- a/tests/models/udop/test_processor_udop.py +++ b/tests/models/udop/test_processor_udop.py @@ -15,7 +15,6 @@ import shutil import tempfile import unittest -from typing import List from transformers import ( PreTrainedTokenizer, @@ -83,7 +82,7 @@ class UdopProcessorTest(ProcessorTesterMixin, unittest.TestCase): def get_rust_tokenizer(self, **kwargs) -> PreTrainedTokenizerFast: return self.rust_tokenizer_class.from_pretrained(self.tokenizer_pretrained_name, **kwargs) - def get_tokenizers(self, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(self, **kwargs) -> list[PreTrainedTokenizerBase]: return [self.get_tokenizer(**kwargs), self.get_rust_tokenizer(**kwargs)] def tearDown(self): diff --git a/tests/models/udop/test_tokenization_udop.py b/tests/models/udop/test_tokenization_udop.py index c8490c4cc0..73c36944d3 100644 --- a/tests/models/udop/test_tokenization_udop.py +++ b/tests/models/udop/test_tokenization_udop.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,6 @@ import inspect import shutil import tempfile import unittest -from typing import List from transformers import ( AddedToken, @@ -162,7 +160,7 @@ class UdopTokenizationTest(TokenizerTesterMixin, unittest.TestCase): assert encoded_pair == text + [1] + text_2 + [1] def test_add_special_tokens(self): - tokenizers: List[UdopTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[UdopTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): special_token = "[SPECIAL_TOKEN]" @@ -178,7 +176,7 @@ class UdopTokenizationTest(TokenizerTesterMixin, unittest.TestCase): self.assertTrue(special_token not in decoded) def test_add_tokens_tokenizer(self): - tokenizers: List[UdopTokenizer] = self.get_tokenizers(do_lower_case=False) + tokenizers: list[UdopTokenizer] = self.get_tokenizers(do_lower_case=False) for tokenizer in tokenizers: with self.subTest(f"{tokenizer.__class__.__name__}"): vocab_size = tokenizer.vocab_size diff --git a/tests/models/umt5/__init__.py b/tests/models/umt5/__init__.py index 8b13789179..e69de29bb2 100644 --- a/tests/models/umt5/__init__.py +++ b/tests/models/umt5/__init__.py @@ -1 +0,0 @@ - diff --git a/tests/models/unispeech/test_modeling_unispeech.py b/tests/models/unispeech/test_modeling_unispeech.py index 2b18aa6588..0f8e244832 100644 --- a/tests/models/unispeech/test_modeling_unispeech.py +++ b/tests/models/unispeech/test_modeling_unispeech.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/unispeech_sat/test_modeling_unispeech_sat.py b/tests/models/unispeech_sat/test_modeling_unispeech_sat.py index ce8cd4180b..dd8deafc22 100644 --- a/tests/models/unispeech_sat/test_modeling_unispeech_sat.py +++ b/tests/models/unispeech_sat/test_modeling_unispeech_sat.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/upernet/test_modeling_upernet.py b/tests/models/upernet/test_modeling_upernet.py index d731ca9588..861608553a 100644 --- a/tests/models/upernet/test_modeling_upernet.py +++ b/tests/models/upernet/test_modeling_upernet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/video_llava/test_image_processing_video_llava.py b/tests/models/video_llava/test_image_processing_video_llava.py index bda655bce6..9678c94fa7 100644 --- a/tests/models/video_llava/test_image_processing_video_llava.py +++ b/tests/models/video_llava/test_image_processing_video_llava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/video_llava/test_modeling_video_llava.py b/tests/models/video_llava/test_modeling_video_llava.py index 208c793a9b..772356e097 100644 --- a/tests/models/video_llava/test_modeling_video_llava.py +++ b/tests/models/video_llava/test_modeling_video_llava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/videomae/test_image_processing_videomae.py b/tests/models/videomae/test_image_processing_videomae.py index f4e2b26fb8..2fe9303f37 100644 --- a/tests/models/videomae/test_image_processing_videomae.py +++ b/tests/models/videomae/test_image_processing_videomae.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/videomae/test_modeling_videomae.py b/tests/models/videomae/test_modeling_videomae.py index 8f1ab7de05..6389fbd677 100644 --- a/tests/models/videomae/test_modeling_videomae.py +++ b/tests/models/videomae/test_modeling_videomae.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vilt/test_image_processing_vilt.py b/tests/models/vilt/test_image_processing_vilt.py index bfd70694aa..74fd5ba8b0 100644 --- a/tests/models/vilt/test_image_processing_vilt.py +++ b/tests/models/vilt/test_image_processing_vilt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vilt/test_modeling_vilt.py b/tests/models/vilt/test_modeling_vilt.py index f85a851dd0..4489ee7f3c 100644 --- a/tests/models/vilt/test_modeling_vilt.py +++ b/tests/models/vilt/test_modeling_vilt.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vipllava/test_modeling_vipllava.py b/tests/models/vipllava/test_modeling_vipllava.py index 47495b2ce3..e79593efbf 100644 --- a/tests/models/vipllava/test_modeling_vipllava.py +++ b/tests/models/vipllava/test_modeling_vipllava.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py b/tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py index bec79869ae..3c70f5a81e 100644 --- a/tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py +++ b/tests/models/vision_encoder_decoder/test_modeling_flax_vision_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -252,7 +251,7 @@ class FlaxEncoderDecoderMixin: self.check_encoder_decoder_model_generate(**config_inputs_dict) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") @slow diff --git a/tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py b/tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py index 337037229a..0810789ce0 100644 --- a/tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py +++ b/tests/models/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -341,7 +340,7 @@ class TFVisionEncoderDecoderMixin: self.check_encoder_decoder_model_generate(**config_inputs_dict) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and tf is {diff} (>= {tol}).") @slow diff --git a/tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py b/tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py index 317048550e..bfd9aad233 100644 --- a/tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py +++ b/tests/models/vision_encoder_decoder/test_modeling_vision_encoder_decoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py b/tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py index 115cdf444f..cc0a0fa212 100644 --- a/tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py +++ b/tests/models/vision_text_dual_encoder/test_modeling_flax_vision_text_dual_encoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -65,7 +64,7 @@ class VisionTextDualEncoderMixin: pass def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") def check_model_from_pretrained_configs( diff --git a/tests/models/vision_text_dual_encoder/test_modeling_tf_vision_text_dual_encoder.py b/tests/models/vision_text_dual_encoder/test_modeling_tf_vision_text_dual_encoder.py index eeb8951edb..b24a5dfb67 100644 --- a/tests/models/vision_text_dual_encoder/test_modeling_tf_vision_text_dual_encoder.py +++ b/tests/models/vision_text_dual_encoder/test_modeling_tf_vision_text_dual_encoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -150,7 +149,7 @@ class TFVisionTextDualEncoderMixin: ) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") def test_vision_text_dual_encoder_model(self): diff --git a/tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py b/tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py index ab10f3e93f..ea04919e49 100644 --- a/tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py +++ b/tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -163,7 +162,7 @@ class VisionTextDualEncoderMixin: ) def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") def test_vision_text_dual_encoder_model(self): diff --git a/tests/models/visual_bert/test_modeling_visual_bert.py b/tests/models/visual_bert/test_modeling_visual_bert.py index 1c32f26a62..b214a13635 100644 --- a/tests/models/visual_bert/test_modeling_visual_bert.py +++ b/tests/models/visual_bert/test_modeling_visual_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vit/test_image_processing_vit.py b/tests/models/vit/test_image_processing_vit.py index 259eb8c960..116316199b 100644 --- a/tests/models/vit/test_image_processing_vit.py +++ b/tests/models/vit/test_image_processing_vit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vit/test_modeling_tf_vit.py b/tests/models/vit/test_modeling_tf_vit.py index a13119436f..6fa3d93d41 100644 --- a/tests/models/vit/test_modeling_tf_vit.py +++ b/tests/models/vit/test_modeling_tf_vit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vit/test_modeling_vit.py b/tests/models/vit/test_modeling_vit.py index 32812e3328..b75df136d3 100644 --- a/tests/models/vit/test_modeling_vit.py +++ b/tests/models/vit/test_modeling_vit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vit_mae/test_modeling_tf_vit_mae.py b/tests/models/vit_mae/test_modeling_tf_vit_mae.py index dcdf6d71e9..3154e13106 100644 --- a/tests/models/vit_mae/test_modeling_tf_vit_mae.py +++ b/tests/models/vit_mae/test_modeling_tf_vit_mae.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vit_mae/test_modeling_vit_mae.py b/tests/models/vit_mae/test_modeling_vit_mae.py index a66bb44e82..c2265b076e 100644 --- a/tests/models/vit_mae/test_modeling_vit_mae.py +++ b/tests/models/vit_mae/test_modeling_vit_mae.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vit_msn/test_modeling_vit_msn.py b/tests/models/vit_msn/test_modeling_vit_msn.py index e437ce75ca..4fd3209897 100644 --- a/tests/models/vit_msn/test_modeling_vit_msn.py +++ b/tests/models/vit_msn/test_modeling_vit_msn.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vitdet/test_modeling_vitdet.py b/tests/models/vitdet/test_modeling_vitdet.py index 4b5ac0f337..c81fe2415c 100644 --- a/tests/models/vitdet/test_modeling_vitdet.py +++ b/tests/models/vitdet/test_modeling_vitdet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vitmatte/test_image_processing_vitmatte.py b/tests/models/vitmatte/test_image_processing_vitmatte.py index 340957fd3e..593f8c5e5e 100644 --- a/tests/models/vitmatte/test_image_processing_vitmatte.py +++ b/tests/models/vitmatte/test_image_processing_vitmatte.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vitmatte/test_modeling_vitmatte.py b/tests/models/vitmatte/test_modeling_vitmatte.py index b75cfc886c..3a94d8c8e1 100644 --- a/tests/models/vitmatte/test_modeling_vitmatte.py +++ b/tests/models/vitmatte/test_modeling_vitmatte.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vitpose/test_image_processing_vitpose.py b/tests/models/vitpose/test_image_processing_vitpose.py index 238fe20aa6..44d9ddf8eb 100644 --- a/tests/models/vitpose/test_image_processing_vitpose.py +++ b/tests/models/vitpose/test_image_processing_vitpose.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vitpose/test_modeling_vitpose.py b/tests/models/vitpose/test_modeling_vitpose.py index a47e9ca737..8f6716f60c 100644 --- a/tests/models/vitpose/test_modeling_vitpose.py +++ b/tests/models/vitpose/test_modeling_vitpose.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vitpose_backbone/test_modeling_vitpose_backbone.py b/tests/models/vitpose_backbone/test_modeling_vitpose_backbone.py index 3e7d598b5b..dec4e7adfa 100644 --- a/tests/models/vitpose_backbone/test_modeling_vitpose_backbone.py +++ b/tests/models/vitpose_backbone/test_modeling_vitpose_backbone.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vits/test_modeling_vits.py b/tests/models/vits/test_modeling_vits.py index 42524ebf8b..5551d0f8be 100644 --- a/tests/models/vits/test_modeling_vits.py +++ b/tests/models/vits/test_modeling_vits.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ import copy import os import tempfile import unittest -from typing import Dict, List, Tuple import numpy as np @@ -287,10 +285,10 @@ class VitsModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): diff --git a/tests/models/vits/test_tokenization_vits.py b/tests/models/vits/test_tokenization_vits.py index 98b02ca5fd..af58762a5a 100644 --- a/tests/models/vits/test_tokenization_vits.py +++ b/tests/models/vits/test_tokenization_vits.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vivit/test_image_processing_vivit.py b/tests/models/vivit/test_image_processing_vivit.py index 3d05a36689..bf61fc1082 100644 --- a/tests/models/vivit/test_image_processing_vivit.py +++ b/tests/models/vivit/test_image_processing_vivit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/vivit/test_modeling_vivit.py b/tests/models/vivit/test_modeling_vivit.py index 364998eb65..2b71b081fe 100644 --- a/tests/models/vivit/test_modeling_vivit.py +++ b/tests/models/vivit/test_modeling_vivit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2/test_feature_extraction_wav2vec2.py b/tests/models/wav2vec2/test_feature_extraction_wav2vec2.py index 2a92ce3ac3..70532e83bd 100644 --- a/tests/models/wav2vec2/test_feature_extraction_wav2vec2.py +++ b/tests/models/wav2vec2/test_feature_extraction_wav2vec2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py b/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py index 593d627ccf..b6585baa11 100644 --- a/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2/test_modeling_wav2vec2.py b/tests/models/wav2vec2/test_modeling_wav2vec2.py index 073d21de65..edafba90ca 100644 --- a/tests/models/wav2vec2/test_modeling_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_wav2vec2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2/test_tokenization_wav2vec2.py b/tests/models/wav2vec2/test_tokenization_wav2vec2.py index 57b2dba414..34f4c7c5bf 100644 --- a/tests/models/wav2vec2/test_tokenization_wav2vec2.py +++ b/tests/models/wav2vec2/test_tokenization_wav2vec2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py b/tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py index 7f1e1b9224..1408e09744 100644 --- a/tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py +++ b/tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py b/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py index 6a884ba36b..f980582024 100644 --- a/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py +++ b/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py b/tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py index f9d547acdd..c67fe60434 100644 --- a/tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py +++ b/tests/models/wav2vec2_phoneme/test_tokenization_wav2vec2_phoneme.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +17,6 @@ import json import os import unittest from functools import lru_cache -from typing import Tuple from transformers import Wav2Vec2PhonemeCTCTokenizer from transformers.models.wav2vec2.tokenization_wav2vec2 import VOCAB_FILES_NAMES @@ -62,7 +60,7 @@ class Wav2Vec2PhonemeCTCTokenizerTest(TokenizerTesterMixin, unittest.TestCase): fp.write(json.dumps(vocab_tokens) + "\n") # overwrite since phonemes require specific creation - def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> Tuple[str, list]: + def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> tuple[str, list]: toks = [(i, tokenizer.decode([i], clean_up_tokenization_spaces=False)) for i in range(len(tokenizer))] toks = list(filter(lambda t: [t[0]] == tokenizer.encode(t[1], do_phonemize=False), toks)) if max_length is not None and len(toks) > max_length: diff --git a/tests/models/wavlm/test_modeling_wavlm.py b/tests/models/wavlm/test_modeling_wavlm.py index 228587c2be..618e8c3ffa 100644 --- a/tests/models/wavlm/test_modeling_wavlm.py +++ b/tests/models/wavlm/test_modeling_wavlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/whisper/test_feature_extraction_whisper.py b/tests/models/whisper/test_feature_extraction_whisper.py index 80cb421d13..228e0cabc0 100644 --- a/tests/models/whisper/test_feature_extraction_whisper.py +++ b/tests/models/whisper/test_feature_extraction_whisper.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/whisper/test_modeling_flax_whisper.py b/tests/models/whisper/test_modeling_flax_whisper.py index 274582be23..ee583c8719 100644 --- a/tests/models/whisper/test_modeling_flax_whisper.py +++ b/tests/models/whisper/test_modeling_flax_whisper.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/whisper/test_modeling_tf_whisper.py b/tests/models/whisper/test_modeling_tf_whisper.py index 20109ef2aa..71c1f4dc22 100644 --- a/tests/models/whisper/test_modeling_tf_whisper.py +++ b/tests/models/whisper/test_modeling_tf_whisper.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/whisper/test_modeling_whisper.py b/tests/models/whisper/test_modeling_whisper.py index f4a1f8e506..ff13b5eef5 100644 --- a/tests/models/whisper/test_modeling_whisper.py +++ b/tests/models/whisper/test_modeling_whisper.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/x_clip/test_modeling_x_clip.py b/tests/models/x_clip/test_modeling_x_clip.py index 5a121d7743..161e30ee2e 100644 --- a/tests/models/x_clip/test_modeling_x_clip.py +++ b/tests/models/x_clip/test_modeling_x_clip.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xglm/test_modeling_flax_xglm.py b/tests/models/xglm/test_modeling_flax_xglm.py index 0eaf5d46af..8e0d644885 100644 --- a/tests/models/xglm/test_modeling_flax_xglm.py +++ b/tests/models/xglm/test_modeling_flax_xglm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -132,7 +131,7 @@ class FlaxXGLMModelTester: outputs = model(input_ids) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") def check_use_cache_forward_with_attn_mask(self, model_class_name, config, input_ids, attention_mask): @@ -164,7 +163,7 @@ class FlaxXGLMModelTester: ) outputs = model(input_ids, attention_mask=attention_mask) - diff = np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5]))) + diff = np.max(np.abs(outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])) self.parent.assertTrue(diff < 1e-3, msg=f"Max diff is {diff}") diff --git a/tests/models/xglm/test_modeling_tf_xglm.py b/tests/models/xglm/test_modeling_tf_xglm.py index 5609400327..1fa58bd3d3 100644 --- a/tests/models/xglm/test_modeling_tf_xglm.py +++ b/tests/models/xglm/test_modeling_tf_xglm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xglm/test_modeling_xglm.py b/tests/models/xglm/test_modeling_xglm.py index 31c298132e..6a4b0553bc 100644 --- a/tests/models/xglm/test_modeling_xglm.py +++ b/tests/models/xglm/test_modeling_xglm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xglm/test_tokenization_xglm.py b/tests/models/xglm/test_tokenization_xglm.py index 08fa3ebf1a..f7131d7e03 100644 --- a/tests/models/xglm/test_tokenization_xglm.py +++ b/tests/models/xglm/test_tokenization_xglm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm/test_modeling_tf_xlm.py b/tests/models/xlm/test_modeling_tf_xlm.py index f9172a1b4e..b0a20ce0c6 100644 --- a/tests/models/xlm/test_modeling_tf_xlm.py +++ b/tests/models/xlm/test_modeling_tf_xlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm/test_modeling_xlm.py b/tests/models/xlm/test_modeling_xlm.py index 17ba172972..74033a590e 100644 --- a/tests/models/xlm/test_modeling_xlm.py +++ b/tests/models/xlm/test_modeling_xlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm/test_tokenization_xlm.py b/tests/models/xlm/test_tokenization_xlm.py index 2292b18b8b..7e5c8f688a 100644 --- a/tests/models/xlm/test_tokenization_xlm.py +++ b/tests/models/xlm/test_tokenization_xlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm_roberta/test_modeling_flax_xlm_roberta.py b/tests/models/xlm_roberta/test_modeling_flax_xlm_roberta.py index 6af8060060..17ae593b16 100644 --- a/tests/models/xlm_roberta/test_modeling_flax_xlm_roberta.py +++ b/tests/models/xlm_roberta/test_modeling_flax_xlm_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm_roberta/test_modeling_tf_xlm_roberta.py b/tests/models/xlm_roberta/test_modeling_tf_xlm_roberta.py index 1ecac55310..f28038bc22 100644 --- a/tests/models/xlm_roberta/test_modeling_tf_xlm_roberta.py +++ b/tests/models/xlm_roberta/test_modeling_tf_xlm_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm_roberta/test_modeling_xlm_roberta.py b/tests/models/xlm_roberta/test_modeling_xlm_roberta.py index d9aac95781..bad6e266ea 100644 --- a/tests/models/xlm_roberta/test_modeling_xlm_roberta.py +++ b/tests/models/xlm_roberta/test_modeling_xlm_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm_roberta/test_tokenization_xlm_roberta.py b/tests/models/xlm_roberta/test_tokenization_xlm_roberta.py index ba5a834bfe..0d5d8a43b6 100644 --- a/tests/models/xlm_roberta/test_tokenization_xlm_roberta.py +++ b/tests/models/xlm_roberta/test_tokenization_xlm_roberta.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py b/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py index 094f977f15..513277c77c 100644 --- a/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py +++ b/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlnet/test_modeling_tf_xlnet.py b/tests/models/xlnet/test_modeling_tf_xlnet.py index 71a308bf52..e9708a5807 100644 --- a/tests/models/xlnet/test_modeling_tf_xlnet.py +++ b/tests/models/xlnet/test_modeling_tf_xlnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlnet/test_modeling_xlnet.py b/tests/models/xlnet/test_modeling_xlnet.py index 23a9ee0d89..b8bed5c822 100644 --- a/tests/models/xlnet/test_modeling_xlnet.py +++ b/tests/models/xlnet/test_modeling_xlnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xlnet/test_tokenization_xlnet.py b/tests/models/xlnet/test_tokenization_xlnet.py index 307499b605..15a7b718d0 100644 --- a/tests/models/xlnet/test_tokenization_xlnet.py +++ b/tests/models/xlnet/test_tokenization_xlnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/xmod/test_modeling_xmod.py b/tests/models/xmod/test_modeling_xmod.py index fd0be2da7e..754384534b 100644 --- a/tests/models/xmod/test_modeling_xmod.py +++ b/tests/models/xmod/test_modeling_xmod.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/yolos/test_image_processing_yolos.py b/tests/models/yolos/test_image_processing_yolos.py index e3b4dc409c..69748d9e55 100644 --- a/tests/models/yolos/test_image_processing_yolos.py +++ b/tests/models/yolos/test_image_processing_yolos.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -220,7 +219,7 @@ class YolosImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMix def test_call_pytorch_with_coco_detection_annotations(self): # prepare image and target image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) target = {"image_id": 39769, "annotations": target} @@ -264,7 +263,7 @@ class YolosImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMix def test_call_pytorch_with_coco_panoptic_annotations(self): # prepare image, target and masks_path image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) target = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} @@ -315,7 +314,7 @@ class YolosImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMix image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt") as f: target = json.loads(f.read()) annotations_0 = {"image_id": 39769, "annotations": target} @@ -434,7 +433,7 @@ class YolosImageProcessingTest(AnnotationFormatTestMixin, ImageProcessingTestMix image_0 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png") image_1 = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png").resize((800, 800)) - with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt", "r") as f: + with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt") as f: target = json.loads(f.read()) annotation_0 = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": target} diff --git a/tests/models/yolos/test_modeling_yolos.py b/tests/models/yolos/test_modeling_yolos.py index bfc428961c..d7b13f5846 100644 --- a/tests/models/yolos/test_modeling_yolos.py +++ b/tests/models/yolos/test_modeling_yolos.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/yoso/test_modeling_yoso.py b/tests/models/yoso/test_modeling_yoso.py index cb31efcd57..621cb184e8 100644 --- a/tests/models/yoso/test_modeling_yoso.py +++ b/tests/models/yoso/test_modeling_yoso.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/zamba/test_modeling_zamba.py b/tests/models/zamba/test_modeling_zamba.py index 88023f6c1a..f8574de00f 100644 --- a/tests/models/zamba/test_modeling_zamba.py +++ b/tests/models/zamba/test_modeling_zamba.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/zamba2/test_modeling_zamba2.py b/tests/models/zamba2/test_modeling_zamba2.py index 58f6b8e595..8c9b07ce89 100644 --- a/tests/models/zamba2/test_modeling_zamba2.py +++ b/tests/models/zamba2/test_modeling_zamba2.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/zoedepth/test_image_processing_zoedepth.py b/tests/models/zoedepth/test_image_processing_zoedepth.py index ba4986c46f..69558ad3c4 100644 --- a/tests/models/zoedepth/test_image_processing_zoedepth.py +++ b/tests/models/zoedepth/test_image_processing_zoedepth.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/models/zoedepth/test_modeling_zoedepth.py b/tests/models/zoedepth/test_modeling_zoedepth.py index e9ffae7f5c..4fd271c697 100644 --- a/tests/models/zoedepth/test_modeling_zoedepth.py +++ b/tests/models/zoedepth/test_modeling_zoedepth.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/optimization/test_optimization.py b/tests/optimization/test_optimization.py index 73b09c0627..51c66e086f 100644 --- a/tests/optimization/test_optimization.py +++ b/tests/optimization/test_optimization.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/peft_integration/test_peft_integration.py b/tests/peft_integration/test_peft_integration.py index 22282aa07f..5bb16e4241 100644 --- a/tests/peft_integration/test_peft_integration.py +++ b/tests/peft_integration/test_peft_integration.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index d35f5978cd..5dde697d1c 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -430,8 +430,7 @@ class PipelineUtilsTest(unittest.TestCase): from transformers.pipelines.pt_utils import PipelineIterator def dummy_dataset(): - for i in range(4): - yield i + yield from range(4) def add(number, extra=0): return number + extra @@ -480,8 +479,7 @@ class PipelineUtilsTest(unittest.TestCase): from transformers.pipelines.pt_utils import PipelineChunkIterator def preprocess_chunk(n: int): - for i in range(n): - yield i + yield from range(n) dataset = [2, 3] diff --git a/tests/pipelines/test_pipelines_image_segmentation.py b/tests/pipelines/test_pipelines_image_segmentation.py index 62e56556dd..36e6460231 100644 --- a/tests/pipelines/test_pipelines_image_segmentation.py +++ b/tests/pipelines/test_pipelines_image_segmentation.py @@ -14,7 +14,6 @@ import tempfile import unittest -from typing import Dict import datasets import numpy as np @@ -65,14 +64,14 @@ def hashimage(image: Image) -> str: return m.hexdigest()[:10] -def mask_to_test_readable(mask: Image) -> Dict: +def mask_to_test_readable(mask: Image) -> dict: npimg = np.array(mask) white_pixels = (npimg == 255).sum() shape = npimg.shape return {"hash": hashimage(mask), "white_pixels": white_pixels, "shape": shape} -def mask_to_test_readable_only_shape(mask: Image) -> Dict: +def mask_to_test_readable_only_shape(mask: Image) -> dict: npimg = np.array(mask) shape = npimg.shape return {"shape": shape} diff --git a/tests/pipelines/test_pipelines_mask_generation.py b/tests/pipelines/test_pipelines_mask_generation.py index 4adfff49e1..1002f7e633 100644 --- a/tests/pipelines/test_pipelines_mask_generation.py +++ b/tests/pipelines/test_pipelines_mask_generation.py @@ -13,7 +13,6 @@ # limitations under the License. import unittest -from typing import Dict import numpy as np from huggingface_hub.utils import insecure_hashlib @@ -50,7 +49,7 @@ def hashimage(image: Image) -> str: return m.hexdigest()[:10] -def mask_to_test_readable(mask: Image) -> Dict: +def mask_to_test_readable(mask: Image) -> dict: npimg = np.array(mask) shape = npimg.shape return {"hash": hashimage(mask), "shape": shape} @@ -60,11 +59,9 @@ def mask_to_test_readable(mask: Image) -> Dict: @require_vision @require_torch class MaskGenerationPipelineTests(unittest.TestCase): - model_mapping = dict( - (list(MODEL_FOR_MASK_GENERATION_MAPPING.items()) if MODEL_FOR_MASK_GENERATION_MAPPING else []) - ) + model_mapping = dict(list(MODEL_FOR_MASK_GENERATION_MAPPING.items()) if MODEL_FOR_MASK_GENERATION_MAPPING else []) tf_model_mapping = dict( - (list(TF_MODEL_FOR_MASK_GENERATION_MAPPING.items()) if TF_MODEL_FOR_MASK_GENERATION_MAPPING else []) + list(TF_MODEL_FOR_MASK_GENERATION_MAPPING.items()) if TF_MODEL_FOR_MASK_GENERATION_MAPPING else [] ) def get_test_pipeline( diff --git a/tests/pipelines/test_pipelines_visual_question_answering.py b/tests/pipelines/test_pipelines_visual_question_answering.py index 3c79dc7faa..a4b1a9b795 100644 --- a/tests/pipelines/test_pipelines_visual_question_answering.py +++ b/tests/pipelines/test_pipelines_visual_question_answering.py @@ -131,7 +131,7 @@ class VisualQuestionAnsweringPipelineTests(unittest.TestCase): model_kwargs={"torch_dtype": torch.float16}, device=torch_device, ) - self.assertEqual(vqa_pipeline.model.device, torch.device("{}:0".format(torch_device))) + self.assertEqual(vqa_pipeline.model.device, torch.device(f"{torch_device}:0")) self.assertEqual(vqa_pipeline.model.language_model.dtype, torch.float16) self.assertEqual(vqa_pipeline.model.vision_model.dtype, torch.float16) @@ -173,7 +173,7 @@ class VisualQuestionAnsweringPipelineTests(unittest.TestCase): model_kwargs={"torch_dtype": torch.float16}, device=torch_device, ) - self.assertEqual(vqa_pipeline.model.device, torch.device("{}:0".format(torch_device))) + self.assertEqual(vqa_pipeline.model.device, torch.device(f"{torch_device}:0")) self.assertEqual(vqa_pipeline.model.language_model.dtype, torch.float16) image = "./tests/fixtures/tests_samples/COCO/000000039769.png" diff --git a/tests/quantization/aqlm_integration/test_aqlm.py b/tests/quantization/aqlm_integration/test_aqlm.py index d5d45f43cc..03cf79dafa 100644 --- a/tests/quantization/aqlm_integration/test_aqlm.py +++ b/tests/quantization/aqlm_integration/test_aqlm.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/autoawq/test_awq.py b/tests/quantization/autoawq/test_awq.py index 913c6636b1..95e26e18c8 100644 --- a/tests/quantization/autoawq/test_awq.py +++ b/tests/quantization/autoawq/test_awq.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/bitnet_integration/test_bitnet.py b/tests/quantization/bitnet_integration/test_bitnet.py index dc6a2546cc..537f0a0da2 100644 --- a/tests/quantization/bitnet_integration/test_bitnet.py +++ b/tests/quantization/bitnet_integration/test_bitnet.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/bnb/test_4bit.py b/tests/quantization/bnb/test_4bit.py index 2d40e90104..967e2cfa16 100644 --- a/tests/quantization/bnb/test_4bit.py +++ b/tests/quantization/bnb/test_4bit.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/bnb/test_mixed_int8.py b/tests/quantization/bnb/test_mixed_int8.py index 26191baa4e..4e954bafb3 100644 --- a/tests/quantization/bnb/test_mixed_int8.py +++ b/tests/quantization/bnb/test_mixed_int8.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 The HuggingFace Team Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/eetq_integration/test_eetq.py b/tests/quantization/eetq_integration/test_eetq.py index b1453f85ea..a5e989ca94 100644 --- a/tests/quantization/eetq_integration/test_eetq.py +++ b/tests/quantization/eetq_integration/test_eetq.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py b/tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py index 3efff115ba..d3ecbb671f 100644 --- a/tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py +++ b/tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/finegrained_fp8/test_fp8.py b/tests/quantization/finegrained_fp8/test_fp8.py index 69881b4cbb..83bdea1e66 100644 --- a/tests/quantization/finegrained_fp8/test_fp8.py +++ b/tests/quantization/finegrained_fp8/test_fp8.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/ggml/test_ggml.py b/tests/quantization/ggml/test_ggml.py index efba55d42b..59b7e32b96 100644 --- a/tests/quantization/ggml/test_ggml.py +++ b/tests/quantization/ggml/test_ggml.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/gptq/test_gptq.py b/tests/quantization/gptq/test_gptq.py index d2b3ddf853..f665ee07f1 100644 --- a/tests/quantization/gptq/test_gptq.py +++ b/tests/quantization/gptq/test_gptq.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/higgs/test_higgs.py b/tests/quantization/higgs/test_higgs.py index 687a4ab22f..65dd151e98 100644 --- a/tests/quantization/higgs/test_higgs.py +++ b/tests/quantization/higgs/test_higgs.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/hqq/test_hqq.py b/tests/quantization/hqq/test_hqq.py index 031b3fefa5..221248d788 100755 --- a/tests/quantization/hqq/test_hqq.py +++ b/tests/quantization/hqq/test_hqq.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/quanto_integration/test_quanto.py b/tests/quantization/quanto_integration/test_quanto.py index 9660694c51..50685137cb 100644 --- a/tests/quantization/quanto_integration/test_quanto.py +++ b/tests/quantization/quanto_integration/test_quanto.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/quark_integration/test_quark.py b/tests/quantization/quark_integration/test_quark.py index 32a9f6a6d8..728ca36482 100644 --- a/tests/quantization/quark_integration/test_quark.py +++ b/tests/quantization/quark_integration/test_quark.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2025 Advanced Micro Devices, Inc. and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/spqr_integration/test_spqr.py b/tests/quantization/spqr_integration/test_spqr.py index 425cce664c..961d11478c 100644 --- a/tests/quantization/spqr_integration/test_spqr.py +++ b/tests/quantization/spqr_integration/test_spqr.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/torchao_integration/test_torchao.py b/tests/quantization/torchao_integration/test_torchao.py index 5f4a21e073..3f24d9a95a 100644 --- a/tests/quantization/torchao_integration/test_torchao.py +++ b/tests/quantization/torchao_integration/test_torchao.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/quantization/vptq_integration/test_vptq.py b/tests/quantization/vptq_integration/test_vptq.py index 173afa7d00..fdbd703bae 100644 --- a/tests/quantization/vptq_integration/test_vptq.py +++ b/tests/quantization/vptq_integration/test_vptq.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -156,7 +155,7 @@ class VptqTest(unittest.TestCase): for name in names: shared_layer_config[name] = value for i in range(24): - modules_to_not_convert.append("model.decoder.layers.{layer_idx}.fc1".format(layer_idx=i)) + modules_to_not_convert.append(f"model.decoder.layers.{i}.fc1") layer_configs = {} layer_configs["model.decoder.project_out"] = value layer_configs["model.decoder.project_in"] = value diff --git a/tests/repo_utils/test_check_copies.py b/tests/repo_utils/test_check_copies.py index 6afed02895..826f1b5956 100644 --- a/tests/repo_utils/test_check_copies.py +++ b/tests/repo_utils/test_check_copies.py @@ -239,7 +239,7 @@ class RobertaBertDummyModel: def replace_in_file(filename, old, new): - with open(filename, "r", encoding="utf-8") as f: + with open(filename, encoding="utf-8") as f: content = f.read() content = content.replace(old, new) @@ -328,7 +328,7 @@ class CopyCheckTester(unittest.TestCase): _ = is_copy_consistent(file_to_check, overwrite=True) - with open(file_to_check, "r", encoding="utf-8") as f: + with open(file_to_check, encoding="utf-8") as f: self.assertEqual(f.read(), MOCK_BERT_COPY_CODE) def test_is_copy_consistent_with_ignored_match(self): @@ -364,7 +364,7 @@ class CopyCheckTester(unittest.TestCase): _ = is_copy_consistent(file_to_check, overwrite=True) - with open(file_to_check, "r", encoding="utf-8") as f: + with open(file_to_check, encoding="utf-8") as f: self.assertEqual(f.read(), EXPECTED_REPLACED_CODE) def test_convert_to_localized_md(self): diff --git a/tests/repo_utils/test_get_test_info.py b/tests/repo_utils/test_get_test_info.py index a6d4a9984d..b478cb1b76 100644 --- a/tests/repo_utils/test_get_test_info.py +++ b/tests/repo_utils/test_get_test_info.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/repo_utils/test_tests_fetcher.py b/tests/repo_utils/test_tests_fetcher.py index dfb81a31b5..8f3f64c1a2 100644 --- a/tests/repo_utils/test_tests_fetcher.py +++ b/tests/repo_utils/test_tests_fetcher.py @@ -646,9 +646,9 @@ src/transformers/configuration_utils.py with patch_transformer_repo_path(tmp_folder): infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True) - with open(tmp_folder / "test-output.txt", "r") as f: + with open(tmp_folder / "test-output.txt") as f: tests_to_run = f.read() - with open(tmp_folder / "examples_test_list.txt", "r") as f: + with open(tmp_folder / "examples_test_list.txt") as f: example_tests_to_run = f.read() assert tests_to_run == "tests/models/bert/test_modeling_bert.py" @@ -687,9 +687,9 @@ src/transformers/configuration_utils.py with patch_transformer_repo_path(tmp_folder): infer_tests_to_run(tmp_folder / "test-output.txt") - with open(tmp_folder / "test-output.txt", "r") as f: + with open(tmp_folder / "test-output.txt") as f: tests_to_run = f.read() - with open(tmp_folder / "examples_test_list.txt", "r") as f: + with open(tmp_folder / "examples_test_list.txt") as f: example_tests_to_run = f.read() expected_tests = { @@ -703,9 +703,9 @@ src/transformers/configuration_utils.py with patch_transformer_repo_path(tmp_folder): infer_tests_to_run(tmp_folder / "test-output.txt", filter_models=False) - with open(tmp_folder / "test-output.txt", "r") as f: + with open(tmp_folder / "test-output.txt") as f: tests_to_run = f.read() - with open(tmp_folder / "examples_test_list.txt", "r") as f: + with open(tmp_folder / "examples_test_list.txt") as f: example_tests_to_run = f.read() expected_tests = [f"tests/models/{name}/test_modeling_{name}.py" for name in models + ["t5"]] @@ -728,7 +728,7 @@ src/transformers/configuration_utils.py with patch_transformer_repo_path(tmp_folder): infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True) - with open(tmp_folder / "test-output.txt", "r") as f: + with open(tmp_folder / "test-output.txt") as f: tests_to_run = f.read() assert tests_to_run == "tests/models/bert/test_modeling_bert.py" @@ -749,7 +749,7 @@ src/transformers/configuration_utils.py with patch_transformer_repo_path(tmp_folder): infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True) - with open(tmp_folder / "examples_test_list.txt", "r") as f: + with open(tmp_folder / "examples_test_list.txt") as f: example_tests_to_run = f.read() assert example_tests_to_run == "examples/pytorch/test_pytorch_examples.py" @@ -764,7 +764,7 @@ src/transformers/configuration_utils.py with patch_transformer_repo_path(tmp_folder): infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True) - with open(tmp_folder / "examples_test_list.txt", "r") as f: + with open(tmp_folder / "examples_test_list.txt") as f: example_tests_to_run = f.read() assert example_tests_to_run == "examples/pytorch/test_pytorch_examples.py" diff --git a/tests/sagemaker/scripts/pytorch/run_glue_model_parallelism.py b/tests/sagemaker/scripts/pytorch/run_glue_model_parallelism.py index e48717914e..64b86c8de1 100644 --- a/tests/sagemaker/scripts/pytorch/run_glue_model_parallelism.py +++ b/tests/sagemaker/scripts/pytorch/run_glue_model_parallelism.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# coding=utf-8 # Copyright 2021 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_backbone_common.py b/tests/test_backbone_common.py index 634ea27d93..d2229ad4b6 100644 --- a/tests/test_backbone_common.py +++ b/tests/test_backbone_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_configuration_common.py b/tests/test_configuration_common.py index c16a888885..4a3871a5c9 100644 --- a/tests/test_configuration_common.py +++ b/tests/test_configuration_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_feature_extraction_common.py b/tests/test_feature_extraction_common.py index 49937309d0..be90ee316e 100644 --- a/tests/test_feature_extraction_common.py +++ b/tests/test_feature_extraction_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_image_processing_common.py b/tests/test_image_processing_common.py index a5627c8b6f..5583d95ebe 100644 --- a/tests/test_image_processing_common.py +++ b/tests/test_image_processing_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -591,7 +590,7 @@ class AnnotationFormatTestMixin: image_processor_dict = self.image_processor_tester.prepare_image_processor_dict() fixtures_path = pathlib.Path(__file__).parent / "fixtures" / "tests_samples" / "COCO" - with open(fixtures_path / "coco_annotations.txt", "r") as f: + with open(fixtures_path / "coco_annotations.txt") as f: detection_target = json.loads(f.read()) detection_annotations = {"image_id": 39769, "annotations": detection_target} @@ -602,7 +601,7 @@ class AnnotationFormatTestMixin: "return_tensors": "pt", } - with open(fixtures_path / "coco_panoptic_annotations.txt", "r") as f: + with open(fixtures_path / "coco_panoptic_annotations.txt") as f: panoptic_target = json.loads(f.read()) panoptic_annotations = {"file_name": "000000039769.png", "image_id": 39769, "segments_info": panoptic_target} diff --git a/tests/test_image_transforms.py b/tests/test_image_transforms.py index 560ea6a36b..66b94c4ee7 100644 --- a/tests/test_image_transforms.py +++ b/tests/test_image_transforms.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2022 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_modeling_common.py b/tests/test_modeling_common.py index 6a47a882d1..401b7df711 100755 --- a/tests/test_modeling_common.py +++ b/tests/test_modeling_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,7 +24,6 @@ import tempfile import warnings from collections import defaultdict from contextlib import contextmanager -from typing import Dict, List, Tuple import numpy as np from packaging import version @@ -2333,10 +2331,10 @@ class ModelTesterMixin: dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) - elif isinstance(tuple_object, Dict): + elif isinstance(tuple_object, dict): for tuple_iterable_value, dict_iterable_value in zip( tuple_object.values(), dict_object.values() ): @@ -2455,7 +2453,7 @@ class ModelTesterMixin: return new_tf_outputs, new_pt_outputs def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") def test_inputs_embeds(self): @@ -2656,7 +2654,7 @@ class ModelTesterMixin: for value, parallel_value in zip(output, parallel_output): if isinstance(value, torch.Tensor): torch.testing.assert_close(value, parallel_value.to("cpu"), rtol=1e-7, atol=1e-7) - elif isinstance(value, (Tuple, List)): + elif isinstance(value, (tuple, list)): for value_, parallel_value_ in zip(value, parallel_value): torch.testing.assert_close(value_, parallel_value_.to("cpu"), rtol=1e-7, atol=1e-7) diff --git a/tests/test_modeling_flax_common.py b/tests/test_modeling_flax_common.py index 82cbf0901c..97aedcb8e4 100644 --- a/tests/test_modeling_flax_common.py +++ b/tests/test_modeling_flax_common.py @@ -17,7 +17,6 @@ import inspect import json import random import tempfile -from typing import List, Tuple import numpy as np @@ -142,7 +141,7 @@ class FlaxModelTesterMixin: return inputs_dict def assert_almost_equals(self, a: np.ndarray, b: np.ndarray, tol: float): - diff = np.abs((a - b)).max() + diff = np.abs(a - b).max() self.assertLessEqual(diff, tol, f"Difference between torch and flax is {diff} (>= {tol}).") def test_model_outputs_equivalence(self): @@ -153,7 +152,7 @@ class FlaxModelTesterMixin: dict_output = model(**dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: @@ -696,7 +695,7 @@ class FlaxModelTesterMixin: self.assertEqual( v.shape, flat_params[k].shape, - "Shapes of {} do not match. Expecting {}, got {}.".format(k, v.shape, flat_params[k].shape), + f"Shapes of {k} do not match. Expecting {v.shape}, got {flat_params[k].shape}.", ) # Check that setting params raises an ValueError when _do_init is False @@ -722,7 +721,7 @@ class FlaxModelTesterMixin: self.assertEqual( v.shape, flat_params[k].shape, - "Shapes of {} do not match. Expecting {}, got {}.".format(k, v.shape, flat_params[k].shape), + f"Shapes of {k} do not match. Expecting {v.shape}, got {flat_params[k].shape}.", ) for model_class in self.all_model_classes: @@ -801,7 +800,7 @@ class FlaxModelTesterMixin: self.assertEqual(len(state_file), 1) # Check the index and the shard files found match - with open(index_file, "r", encoding="utf-8") as f: + with open(index_file, encoding="utf-8") as f: index = json.loads(f.read()) all_shards = set(index["weight_map"].values()) diff --git a/tests/test_modeling_tf_common.py b/tests/test_modeling_tf_common.py index 248b43c2f8..8b9d7dc391 100644 --- a/tests/test_modeling_tf_common.py +++ b/tests/test_modeling_tf_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,7 +24,6 @@ import tempfile import unittest from importlib import import_module from math import isnan -from typing import List, Tuple from datasets import Dataset @@ -731,7 +729,7 @@ class TFModelTesterMixin: dict_output = model(dict_inputs, return_dict=True, **additional_kwargs).to_tuple() def recursive_check(tuple_object, dict_object): - if isinstance(tuple_object, (List, Tuple)): + if isinstance(tuple_object, (list, tuple)): for tuple_iterable_value, dict_iterable_value in zip(tuple_object, dict_object): recursive_check(tuple_iterable_value, dict_iterable_value) elif tuple_object is None: diff --git a/tests/test_pipeline_mixin.py b/tests/test_pipeline_mixin.py index 32969ab0d3..9f6a85b6b1 100644 --- a/tests/test_pipeline_mixin.py +++ b/tests/test_pipeline_mixin.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_processing_common.py b/tests/test_processing_common.py index f4e1e1b543..6daea1fa3b 100644 --- a/tests/test_processing_common.py +++ b/tests/test_processing_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_sequence_feature_extraction_common.py b/tests/test_sequence_feature_extraction_common.py index f63ad1ede4..1c704a4e54 100644 --- a/tests/test_sequence_feature_extraction_common.py +++ b/tests/test_sequence_feature_extraction_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_tokenization_common.py b/tests/test_tokenization_common.py index 6bc870614d..91d96fe214 100644 --- a/tests/test_tokenization_common.py +++ b/tests/test_tokenization_common.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +28,7 @@ from collections import OrderedDict from functools import lru_cache from itertools import takewhile from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Union +from typing import TYPE_CHECKING, Any, Union from parameterized import parameterized @@ -124,11 +123,11 @@ def filter_roberta_detectors(_, pretrained_name: str): def merge_model_tokenizer_mappings( - model_mapping: Dict["PretrainedConfig", Union["PreTrainedModel", "TFPreTrainedModel"]], - tokenizer_mapping: Dict["PretrainedConfig", Tuple["PreTrainedTokenizer", "PreTrainedTokenizerFast"]], -) -> Dict[ + model_mapping: dict["PretrainedConfig", Union["PreTrainedModel", "TFPreTrainedModel"]], + tokenizer_mapping: dict["PretrainedConfig", tuple["PreTrainedTokenizer", "PreTrainedTokenizerFast"]], +) -> dict[ Union["PreTrainedTokenizer", "PreTrainedTokenizerFast"], - Tuple["PretrainedConfig", Union["PreTrainedModel", "TFPreTrainedModel"]], + tuple["PretrainedConfig", Union["PreTrainedModel", "TFPreTrainedModel"]], ]: configurations = list(model_mapping.keys()) model_tokenizer_mapping = OrderedDict([]) @@ -266,7 +265,7 @@ class TokenizerTesterMixin: input_txt = self.get_clean_sequence(tokenizer)[0] return input_txt, input_txt - def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> Tuple[str, list]: + def get_clean_sequence(self, tokenizer, with_prefix_space=False, max_length=20, min_length=5) -> tuple[str, list]: # the length of the tokenizer does not always represent the tokens that it can encode: what if there are holes? toks = [ (i, tokenizer.decode([i], clean_up_tokenization_spaces=False)) for i in set(tokenizer.get_vocab().values()) @@ -294,7 +293,7 @@ class TokenizerTesterMixin: output_ids = tokenizer.encode(output_txt, add_special_tokens=False) return output_txt, output_ids - def get_tokenizers(self, fast=True, **kwargs) -> List[PreTrainedTokenizerBase]: + def get_tokenizers(self, fast=True, **kwargs) -> list[PreTrainedTokenizerBase]: if fast and self.test_rust_tokenizer and self.test_slow_tokenizer: return [self.get_tokenizer(**kwargs), self.get_rust_tokenizer(**kwargs)] elif fast and self.test_rust_tokenizer: @@ -320,11 +319,11 @@ class TokenizerTesterMixin: def tokenizer_integration_test_util( self, - expected_encoding: Dict, + expected_encoding: dict, model_name: str, revision: str = None, - sequences: List[str] = None, - decode_kwargs: Dict[str, Any] = None, + sequences: list[str] = None, + decode_kwargs: dict[str, Any] = None, padding: bool = True, ): """ @@ -4485,7 +4484,7 @@ class TokenizerTesterMixin: AlbertTokenizer.from_pretrained(pretrained_name) else: BertTokenizer.from_pretrained(pretrained_name) - except EnvironmentError as e: + except OSError as e: # Some tokenizer will raised an error before reaching the logged warning because there are no # corresponding files to load error_message = str(e) diff --git a/tests/tokenization/test_tokenization_fast.py b/tests/tokenization/test_tokenization_fast.py index 40b945e272..903dc0c67a 100644 --- a/tests/tokenization/test_tokenization_fast.py +++ b/tests/tokenization/test_tokenization_fast.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/tokenization/test_tokenization_utils.py b/tests/tokenization/test_tokenization_utils.py index a9f2b1cd9b..550d319d9b 100644 --- a/tests/tokenization/test_tokenization_utils.py +++ b/tests/tokenization/test_tokenization_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 HuggingFace Inc.. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index f7e16926f2..c2d279509f 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -4923,8 +4922,7 @@ class TrainerIntegrationWithHubTester(unittest.TestCase): def get_commit_history(self, repo): commit_logs = subprocess.run( "git log".split(), - stderr=subprocess.PIPE, - stdout=subprocess.PIPE, + capture_output=True, check=True, encoding="utf-8", cwd=repo, diff --git a/tests/trainer/test_trainer_distributed.py b/tests/trainer/test_trainer_distributed.py index 86c34c4efd..17f7bee23b 100644 --- a/tests/trainer/test_trainer_distributed.py +++ b/tests/trainer/test_trainer_distributed.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict import numpy as np @@ -148,7 +147,7 @@ if __name__ == "__main__": for dataset_length in [101, 40, 7]: dataset = DummyDataset(dataset_length) - def compute_metrics(p: EvalPrediction) -> Dict: + def compute_metrics(p: EvalPrediction) -> dict: sequential = list(range(len(dataset))) success = p.predictions.tolist() == sequential and p.label_ids.tolist() == sequential if not success and training_args.local_rank == 0: diff --git a/tests/trainer/test_trainer_fsdp.py b/tests/trainer/test_trainer_fsdp.py index 255739a2d7..193846ad2c 100644 --- a/tests/trainer/test_trainer_fsdp.py +++ b/tests/trainer/test_trainer_fsdp.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict from transformers import is_torch_available from transformers.testing_utils import ( @@ -166,7 +165,7 @@ if __name__ == "__main__": device = torch.device(torch.distributed.get_rank()) model = AutoModelForCausalLM.from_pretrained(pretrained_model_name).to(device) - def compute_metrics(p: EvalPrediction) -> Dict[str, bool]: + def compute_metrics(p: EvalPrediction) -> dict[str, bool]: return {"accuracy": (p.predictions == p.label_ids).mean()} trainer = Seq2SeqTrainer( diff --git a/tests/trainer/test_trainer_seq2seq.py b/tests/trainer/test_trainer_seq2seq.py index d43edd19ff..30d34e003a 100644 --- a/tests/trainer/test_trainer_seq2seq.py +++ b/tests/trainer/test_trainer_seq2seq.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/trainer/test_trainer_tpu.py b/tests/trainer/test_trainer_tpu.py index 135153fddd..e7bb3d2640 100644 --- a/tests/trainer/test_trainer_tpu.py +++ b/tests/trainer/test_trainer_tpu.py @@ -20,7 +20,6 @@ # import sys -from typing import Dict from transformers import EvalPrediction, HfArgumentParser, TrainingArguments, is_torch_available from transformers.utils import logging @@ -79,7 +78,7 @@ def main(): for dataset_length in [1001, 256, 15]: dataset = DummyDataset(dataset_length) - def compute_metrics(p: EvalPrediction) -> Dict: + def compute_metrics(p: EvalPrediction) -> dict: sequential = list(range(len(dataset))) success = p.predictions.tolist() == sequential and p.label_ids.tolist() == sequential return {"success": success} diff --git a/tests/trainer/test_trainer_utils.py b/tests/trainer/test_trainer_utils.py index 12c750c6ca..f7957a3c97 100644 --- a/tests/trainer/test_trainer_utils.py +++ b/tests/trainer/test_trainer_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2018 the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_add_new_model_like.py b/tests/utils/test_add_new_model_like.py index 4e755f1d4a..875bf76974 100644 --- a/tests/utils/test_add_new_model_like.py +++ b/tests/utils/test_add_new_model_like.py @@ -92,7 +92,7 @@ class TestAddNewModelLike(unittest.TestCase): f.write(content) def check_result(self, file_name, expected_result): - with open(file_name, "r", encoding="utf-8") as f: + with open(file_name, encoding="utf-8") as f: result = f.read() self.assertEqual(result, expected_result) diff --git a/tests/utils/test_audio_utils.py b/tests/utils/test_audio_utils.py index f8d88b602b..7147a9c893 100644 --- a/tests/utils/test_audio_utils.py +++ b/tests/utils/test_audio_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_cache_utils.py b/tests/utils/test_cache_utils.py index 15a3e44ef8..bbf0268c8b 100644 --- a/tests/utils/test_cache_utils.py +++ b/tests/utils/test_cache_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2023 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_chat_template_utils.py b/tests/utils/test_chat_template_utils.py index 730f64859d..89a2dfa22e 100644 --- a/tests/utils/test_chat_template_utils.py +++ b/tests/utils/test_chat_template_utils.py @@ -13,7 +13,7 @@ # limitations under the License. import unittest -from typing import List, Optional, Tuple, Union +from typing import Optional, Union from transformers.utils import DocstringParsingException, TypeHintParsingException, get_json_schema @@ -119,7 +119,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase): self.assertEqual(schema["function"], expected_schema) def test_nested_list(self): - def fn(x: List[List[Union[str, int]]]): + def fn(x: list[list[Union[str, int]]]): """ Test function @@ -173,7 +173,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase): self.assertEqual(schema["function"], expected_schema) def test_multiple_complex_arguments(self): - def fn(x: List[Union[int, float]], y: Optional[Union[int, str]] = None): + def fn(x: list[Union[int, float]], y: Optional[Union[int, str]] = None): """ Test function @@ -283,7 +283,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase): self.assertEqual(schema["function"], expected_schema) def test_tuple(self): - def fn(x: Tuple[int, str]): + def fn(x: tuple[int, str]): """ Test function @@ -315,7 +315,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase): self.assertEqual(schema["function"], expected_schema) def test_single_element_tuple_fails(self): - def fn(x: Tuple[int]): + def fn(x: tuple[int]): """ Test function @@ -333,7 +333,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase): get_json_schema(fn) def test_ellipsis_type_fails(self): - def fn(x: Tuple[int, ...]): + def fn(x: tuple[int, ...]): """ Test function @@ -446,8 +446,8 @@ class JsonSchemaGeneratorTest(unittest.TestCase): def test_everything_all_at_once(self): def fn( - x: str, y: Optional[List[Union[str, int]]], z: Tuple[Union[str, int], str] = (42, "hello") - ) -> Tuple[int, str]: + x: str, y: Optional[list[Union[str, int]]], z: tuple[Union[str, int], str] = (42, "hello") + ) -> tuple[int, str]: """ Test function with multiple args, and docstring args that we have to strip out. diff --git a/tests/utils/test_cli.py b/tests/utils/test_cli.py index 148f091c27..6a7d313eed 100644 --- a/tests/utils/test_cli.py +++ b/tests/utils/test_cli.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019-present, the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_configuration_utils.py b/tests/utils/test_configuration_utils.py index a6408928f6..0ac880dc25 100644 --- a/tests/utils/test_configuration_utils.py +++ b/tests/utils/test_configuration_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_doc_samples.py b/tests/utils/test_doc_samples.py index 96251aeed0..4dd6b2bffe 100644 --- a/tests/utils/test_doc_samples.py +++ b/tests/utils/test_doc_samples.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019-present, the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +16,7 @@ import logging import os import unittest from pathlib import Path -from typing import List, Union +from typing import Union import transformers from transformers.testing_utils import require_tf, require_torch, slow @@ -35,8 +34,8 @@ class TestCodeExamples(unittest.TestCase): self, directory: Path, identifier: Union[str, None] = None, - ignore_files: Union[List[str], None] = None, - n_identifier: Union[str, List[str], None] = None, + ignore_files: Union[list[str], None] = None, + n_identifier: Union[str, list[str], None] = None, only_modules: bool = True, ): """ @@ -56,7 +55,7 @@ class TestCodeExamples(unittest.TestCase): files = [file for file in files if identifier in file] if n_identifier is not None: - if isinstance(n_identifier, List): + if isinstance(n_identifier, list): for n_ in n_identifier: files = [file for file in files if n_ not in file] else: diff --git a/tests/utils/test_feature_extraction_utils.py b/tests/utils/test_feature_extraction_utils.py index 06121dab5d..b3d8932e7c 100644 --- a/tests/utils/test_feature_extraction_utils.py +++ b/tests/utils/test_feature_extraction_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_generic.py b/tests/utils/test_generic.py index 4af8d7c514..85ac32d224 100644 --- a/tests/utils/test_generic.py +++ b/tests/utils/test_generic.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019-present, the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_hf_argparser.py b/tests/utils/test_hf_argparser.py index 56bb553bf3..6845ea746c 100644 --- a/tests/utils/test_hf_argparser.py +++ b/tests/utils/test_hf_argparser.py @@ -22,7 +22,7 @@ from argparse import Namespace from dataclasses import dataclass, field from enum import Enum from pathlib import Path -from typing import Dict, List, Literal, Optional, Union, get_args, get_origin +from typing import List, Literal, Optional, Union, get_args, get_origin import yaml @@ -93,21 +93,21 @@ class OptionalExample: foo: Optional[int] = None bar: Optional[float] = field(default=None, metadata={"help": "help message"}) baz: Optional[str] = None - ces: Optional[List[str]] = list_field(default=[]) - des: Optional[List[int]] = list_field(default=[]) + ces: Optional[list[str]] = list_field(default=[]) + des: Optional[list[int]] = list_field(default=[]) @dataclass class ListExample: - foo_int: List[int] = list_field(default=[]) - bar_int: List[int] = list_field(default=[1, 2, 3]) - foo_str: List[str] = list_field(default=["Hallo", "Bonjour", "Hello"]) - foo_float: List[float] = list_field(default=[0.1, 0.2, 0.3]) + foo_int: list[int] = list_field(default=[]) + bar_int: list[int] = list_field(default=[1, 2, 3]) + foo_str: list[str] = list_field(default=["Hallo", "Bonjour", "Hello"]) + foo_float: list[float] = list_field(default=[0.1, 0.2, 0.3]) @dataclass class RequiredExample: - required_list: List[int] = field() + required_list: list[int] = field() required_str: str = field() required_enum: BasicEnum = field() @@ -435,11 +435,11 @@ class HfArgumentParserTest(unittest.TestCase): for field in fields.values(): # First verify raw dict - if field.type in (dict, Dict): + if field.type in (dict, dict): raw_dict_fields.append(field) # Next check for `Union` or `Optional` elif get_origin(field.type) == Union: - if any(arg in (dict, Dict) for arg in get_args(field.type)): + if any(arg in (dict, dict) for arg in get_args(field.type)): optional_dict_fields.append(field) # First check: anything in `raw_dict_fields` is very bad @@ -455,7 +455,7 @@ class HfArgumentParserTest(unittest.TestCase): args = get_args(field.type) # These should be returned as `dict`, `str`, ... # we only care about the first two - self.assertIn(args[0], (Dict, dict)) + self.assertIn(args[0], (dict, dict)) self.assertEqual( str(args[1]), "", diff --git a/tests/utils/test_hub_utils.py b/tests/utils/test_hub_utils.py index ec5887bd16..447e81ffd9 100644 --- a/tests/utils/test_hub_utils.py +++ b/tests/utils/test_hub_utils.py @@ -150,7 +150,7 @@ class GetFromCacheTests(unittest.TestCase): _raise_exceptions_for_connection_errors=False, ) # The name is the cached name which is not very easy to test, so instead we load the content. - config = json.loads(open(resolved_file, "r").read()) + config = json.loads(open(resolved_file).read()) self.assertEqual(config["hidden_size"], 768) def test_get_file_from_repo_local(self): diff --git a/tests/utils/test_image_processing_utils.py b/tests/utils/test_image_processing_utils.py index 2e70d78978..1b8a515d69 100644 --- a/tests/utils/test_image_processing_utils.py +++ b/tests/utils/test_image_processing_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_image_utils.py b/tests/utils/test_image_utils.py index 47dc0dc46c..c0d395ef32 100644 --- a/tests/utils/test_image_utils.py +++ b/tests/utils/test_image_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2021 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_model_card.py b/tests/utils/test_model_card.py index 6235bb10ed..1b3ca30400 100644 --- a/tests/utils/test_model_card.py +++ b/tests/utils/test_model_card.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_model_output.py b/tests/utils/test_model_output.py index b484c0e169..00473e8786 100644 --- a/tests/utils/test_model_output.py +++ b/tests/utils/test_model_output.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2020 The Hugging Face Team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_modeling_rope_utils.py b/tests/utils/test_modeling_rope_utils.py index 233fbcde2e..fd9f5887b6 100644 --- a/tests/utils/test_modeling_rope_utils.py +++ b/tests/utils/test_modeling_rope_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_modeling_tf_core.py b/tests/utils/test_modeling_tf_core.py index c1cfc46969..e15a804ef3 100644 --- a/tests/utils/test_modeling_tf_core.py +++ b/tests/utils/test_modeling_tf_core.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_modeling_tf_utils.py b/tests/utils/test_modeling_tf_utils.py index 116af748e6..079b385b51 100644 --- a/tests/utils/test_modeling_tf_utils.py +++ b/tests/utils/test_modeling_tf_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -328,7 +327,7 @@ class TFModelUtilsTest(unittest.TestCase): self.assertEqual(len(state_file), 1) # Check the index and the shard files found match - with open(index_file, "r", encoding="utf-8") as f: + with open(index_file, encoding="utf-8") as f: index = json.loads(f.read()) all_shards = set(index["weight_map"].values()) @@ -367,7 +366,7 @@ class TFModelUtilsTest(unittest.TestCase): self.assertFalse(os.path.isfile(os.path.join(tmp_dir, TF2_WEIGHTS_INDEX_NAME))) # Check the index and the shard files found match - with open(index_file, "r", encoding="utf-8") as f: + with open(index_file, encoding="utf-8") as f: index = json.loads(f.read()) all_shards = set(index["weight_map"].values()) diff --git a/tests/utils/test_modeling_utils.py b/tests/utils/test_modeling_utils.py index 4ec2c49744..0d2f7e8271 100644 --- a/tests/utils/test_modeling_utils.py +++ b/tests/utils/test_modeling_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -236,7 +235,7 @@ if is_torch_available(): except OSError: LOG.info("Loading model %s in offline mode failed as expected", TINY_IMAGE_CLASSIF) else: - self.fail("Loading model {} in offline mode should fail".format(TINY_IMAGE_CLASSIF)) + self.fail(f"Loading model {TINY_IMAGE_CLASSIF} in offline mode should fail") # Download model -> Huggingface Hub not concerned by our offline mode LOG.info("Downloading %s for offline tests", TINY_IMAGE_CLASSIF) @@ -280,7 +279,7 @@ if is_torch_available(): except OSError: LOG.info("Loading model %s in offline mode failed as expected", TINY_IMAGE_CLASSIF) else: - self.fail("Loading model {} in offline mode should fail".format(TINY_IMAGE_CLASSIF)) + self.fail(f"Loading model {TINY_IMAGE_CLASSIF} in offline mode should fail") LOG.info("Downloading %s for offline tests", TINY_IMAGE_CLASSIF) hub_api = HfApi() @@ -574,7 +573,7 @@ class ModelUtilsTest(TestCasePlus): def remove_torch_dtype(model_path): file = f"{model_path}/config.json" - with open(file, "r", encoding="utf-8") as f: + with open(file, encoding="utf-8") as f: s = json.load(f) s.pop("torch_dtype") with open(file, "w", encoding="utf-8") as f: @@ -745,7 +744,7 @@ class ModelUtilsTest(TestCasePlus): self.assertEqual(len(state_dict), 1) # Check the index and the shard files found match - with open(index_file, "r", encoding="utf-8") as f: + with open(index_file, encoding="utf-8") as f: index = json.loads(f.read()) all_shards = set(index["weight_map"].values()) diff --git a/tests/utils/test_offline.py b/tests/utils/test_offline.py index 2b383b357e..357005eb57 100644 --- a/tests/utils/test_offline.py +++ b/tests/utils/test_offline.py @@ -15,7 +15,6 @@ import subprocess import sys import unittest -from typing import Tuple from transformers import BertConfig, BertModel, BertTokenizer, pipeline from transformers.testing_utils import TestCasePlus, require_torch @@ -195,7 +194,7 @@ print("success") stdout, _ = self._execute_with_env(load, run, HF_HUB_OFFLINE="1") self.assertIn("True", stdout) - def _execute_with_env(self, *commands: Tuple[str, ...], should_fail: bool = False, **env) -> Tuple[str, str]: + def _execute_with_env(self, *commands: tuple[str, ...], should_fail: bool = False, **env) -> tuple[str, str]: """Execute Python code with a given environment and return the stdout/stderr as strings. If `should_fail=True`, the command is expected to fail. Otherwise, it should succeed. diff --git a/tests/utils/test_processing_utils.py b/tests/utils/test_processing_utils.py index f669da2538..7b32b534a7 100644 --- a/tests/utils/test_processing_utils.py +++ b/tests/utils/test_processing_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_skip_decorators.py b/tests/utils/test_skip_decorators.py index 6888fea23c..abaefad1bf 100644 --- a/tests/utils/test_skip_decorators.py +++ b/tests/utils/test_skip_decorators.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019-present, the HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/utils/test_tokenization_utils.py b/tests/utils/test_tokenization_utils.py index 0c28f24f4c..ff0f6499fe 100644 --- a/tests/utils/test_tokenization_utils.py +++ b/tests/utils/test_tokenization_utils.py @@ -1,4 +1,3 @@ -# coding=utf-8 # Copyright 2019 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License");