@@ -551,37 +551,94 @@ def test_download_variant_partly(self):
551551 assert sum (f .endswith (this_format ) and not f .endswith (f"{ variant } { this_format } " ) for f in files ) == 3
552552 assert not any (f .endswith (other_format ) for f in files )
553553
554- def test_download_broken_variant (self ):
555- for use_safetensors in [False , True ]:
556- # text encoder is missing no variant and "no_ema" variant weights, so the following can't work
557- for variant in [None , "no_ema" ]:
558- with self .assertRaises (OSError ) as error_context :
559- with tempfile .TemporaryDirectory () as tmpdirname :
560- tmpdirname = StableDiffusionPipeline .from_pretrained (
561- "hf-internal-testing/stable-diffusion-broken-variants" ,
562- cache_dir = tmpdirname ,
563- variant = variant ,
564- use_safetensors = use_safetensors ,
565- )
566-
567- assert "Error no file name" in str (error_context .exception )
568-
569- # text encoder has fp16 variants so we can load it
570- with tempfile .TemporaryDirectory () as tmpdirname :
571- tmpdirname = StableDiffusionPipeline .download (
554+ def test_download_safetensors_only_variant_exists_for_model (self ):
555+ variant = None
556+ use_safetensors = True
557+
558+ # text encoder is missing no variant weights, so the following can't work
559+ with tempfile .TemporaryDirectory () as tmpdirname :
560+ with self .assertRaises (OSError ) as error_context :
561+ tmpdirname = StableDiffusionPipeline .from_pretrained (
572562 "hf-internal-testing/stable-diffusion-broken-variants" ,
563+ cache_dir = tmpdirname ,
564+ variant = variant ,
573565 use_safetensors = use_safetensors ,
566+ )
567+ assert "Error no file name" in str (error_context .exception )
568+
569+ # text encoder has fp16 variants so we can load it
570+ with tempfile .TemporaryDirectory () as tmpdirname :
571+ tmpdirname = StableDiffusionPipeline .download (
572+ "hf-internal-testing/stable-diffusion-broken-variants" ,
573+ use_safetensors = use_safetensors ,
574+ cache_dir = tmpdirname ,
575+ variant = "fp16" ,
576+ )
577+ all_root_files = [t [- 1 ] for t in os .walk (tmpdirname )]
578+ files = [item for sublist in all_root_files for item in sublist ]
579+ # None of the downloaded files should be a non-variant file even if we have some here:
580+ # https://huggingface.co/hf-internal-testing/stable-diffusion-broken-variants/tree/main/unet
581+ assert len (files ) == 15 , f"We should only download 15 files, not { len (files )} "
582+
583+ def test_download_bin_only_variant_exists_for_model (self ):
584+ variant = None
585+ use_safetensors = False
586+
587+ # text encoder is missing Non-variant weights, so the following can't work
588+ with tempfile .TemporaryDirectory () as tmpdirname :
589+ with self .assertRaises (OSError ) as error_context :
590+ tmpdirname = StableDiffusionPipeline .from_pretrained (
591+ "hf-internal-testing/stable-diffusion-broken-variants" ,
574592 cache_dir = tmpdirname ,
575- variant = "fp16" ,
593+ variant = variant ,
594+ use_safetensors = use_safetensors ,
576595 )
596+ assert "Error no file name" in str (error_context .exception )
577597
578- all_root_files = [t [- 1 ] for t in os .walk (tmpdirname )]
579- files = [item for sublist in all_root_files for item in sublist ]
598+ # text encoder has fp16 variants so we can load it
599+ with tempfile .TemporaryDirectory () as tmpdirname :
600+ tmpdirname = StableDiffusionPipeline .download (
601+ "hf-internal-testing/stable-diffusion-broken-variants" ,
602+ use_safetensors = use_safetensors ,
603+ cache_dir = tmpdirname ,
604+ variant = "fp16" ,
605+ )
606+ all_root_files = [t [- 1 ] for t in os .walk (tmpdirname )]
607+ files = [item for sublist in all_root_files for item in sublist ]
608+ # None of the downloaded files should be a non-variant file even if we have some here:
609+ # https://huggingface.co/hf-internal-testing/stable-diffusion-broken-variants/tree/main/unet
610+ assert len (files ) == 15 , f"We should only download 15 files, not { len (files )} "
580611
581- # None of the downloaded files should be a non-variant file even if we have some here:
582- # https://huggingface.co/hf-internal-testing/stable-diffusion-broken-variants/tree/main/unet
583- assert len (files ) == 15 , f"We should only download 15 files, not { len (files )} "
584- # only unet has "no_ema" variant
612+ def test_download_safetensors_variant_does_not_exist_for_model (self ):
613+ variant = "no_ema"
614+ use_safetensors = True
615+
616+ # text encoder is missing no_ema variant weights, so the following can't work
617+ with tempfile .TemporaryDirectory () as tmpdirname :
618+ with self .assertRaises (OSError ) as error_context :
619+ tmpdirname = StableDiffusionPipeline .from_pretrained (
620+ "hf-internal-testing/stable-diffusion-broken-variants" ,
621+ cache_dir = tmpdirname ,
622+ variant = variant ,
623+ use_safetensors = use_safetensors ,
624+ )
625+
626+ assert "Error no file name" in str (error_context .exception )
627+
628+ def test_download_bin_variant_does_not_exist_for_model (self ):
629+ variant = "no_ema"
630+ use_safetensors = False
631+
632+ # text encoder is missing no_ema variant weights, so the following can't work
633+ with tempfile .TemporaryDirectory () as tmpdirname :
634+ with self .assertRaises (OSError ) as error_context :
635+ tmpdirname = StableDiffusionPipeline .from_pretrained (
636+ "hf-internal-testing/stable-diffusion-broken-variants" ,
637+ cache_dir = tmpdirname ,
638+ variant = variant ,
639+ use_safetensors = use_safetensors ,
640+ )
641+ assert "Error no file name" in str (error_context .exception )
585642
586643 def test_local_save_load_index (self ):
587644 prompt = "hello"
0 commit comments