






import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config
@pytest.fixture(scope='''session''' )
def 						_a    (      )							->			int:
 a		  =      10
 a		  =      datasets.Features(
     {
         '''tokens''': datasets.Sequence(datasets.Value('''string''' ) ),
         '''labels''': datasets.Sequence(datasets.ClassLabel(names=['''negative''', '''positive'''] ) ),
         '''answers''': datasets.Sequence(
             {
                 '''text''': datasets.Value('''string''' ),
                 '''answer_start''': datasets.Value('''int32''' ),
             } ),
         '''id''': datasets.Value('''int64''' ),
     } )
 a		  =      datasets.Dataset.from_dict(
     {
         '''tokens''': [['''foo'''] * 5] * n,
         '''labels''': [[1] * 5] * n,
         '''answers''': [{'''answer_start''': [97], '''text''': ['''1976''']}] * 10,
         '''id''': list(range(a ) ),
     }	,							features=a	,							)
 return dataset
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Optional[Any]	,							a :Tuple )							->			str:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''file.arrow''' )
 dataset.map(cache_file_name=a )
 return filename


# FILE_CONTENT + files


UpperCAmelCase__				   =		"\\n    Text data.\n    Second line of data."
@pytest.fixture(scope='''session''' )
def 						_a    (      a :int )							->			Tuple:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt'''
 a		  =      FILE_CONTENT
 with open(a	,							'''w''' ) as f:
  f.write(a )
 return filename
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Dict )							->			List[str]:
 import bza

 a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.bz2'''
 a		  =      bytes(a	,							'''utf-8''' )
 with bza.open(a	,							'''wb''' ) as f:
  f.write(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Tuple )							->			str:
 import gzip

 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''file.txt.gz''' )
 a		  =      bytes(a	,							'''utf-8''' )
 with gzip.open(a	,							'''wb''' ) as f:
  f.write(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :str )							->			Tuple:
 if datasets.config.LZ4_AVAILABLE:
  import lza.frame

  a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.lz4'''
  a		  =      bytes(a	,							'''utf-8''' )
  with lza.frame.open(a	,							'''wb''' ) as f:
   f.write(a )
  return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[str]	,							a :Any )							->			Dict:
 if datasets.config.PY7ZR_AVAILABLE:
  import pyazr

  a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.7z'''
  with pyazr.SevenZipFile(a	,							'''w''' ) as archive:
   archive.write(a	,							arcname=os.path.basename(a ) )
  return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[Any]	,							a :Dict )							->			Tuple:
 import tarfile

 a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.tar'''
 with tarfile.TarFile(a	,							'''w''' ) as f:
  f.add(a	,							arcname=os.path.basename(a ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any] )							->			str:
 import lzma

 a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.xz'''
 a		  =      bytes(a	,							'''utf-8''' )
 with lzma.open(a	,							'''wb''' ) as f:
  f.write(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[Any]	,							a :Union[str, Any] )							->			Tuple:
 import zipfile

 a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename(a ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[Any] )							->			Any:
 if datasets.config.ZSTANDARD_AVAILABLE:
  import zstandard as zstd

  a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.txt.zst'''
  a		  =      bytes(a	,							'''utf-8''' )
  with zstd.open(a	,							'''wb''' ) as f:
   f.write(a )
  return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :str )							->			Union[str, Any]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''file.xml'''
 a		  =      textwrap.dedent(
     '''\
    <?xml version="1.0" encoding="UTF-8" ?>
    <tmx version="1.4">
      <header segtype="sentence" srclang="ca" />
      <body>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>
          <tuv xml:lang="en"><seg>Content 1</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>
          <tuv xml:lang="en"><seg>Content 2</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>
          <tuv xml:lang="en"><seg>Content 3</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>
          <tuv xml:lang="en"><seg>Content 4</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>
          <tuv xml:lang="en"><seg>Content 5</seg></tuv>
        </tu>
      </body>
    </tmx>''' )
 with open(a	,							'''w''' ) as f:
  f.write(a )
 return filename


UpperCAmelCase__				   =		[
    {"col_1": "0", "col_2": 0, "col_3": 0.0},
    {"col_1": "1", "col_2": 1, "col_3": 1.0},
    {"col_1": "2", "col_2": 2, "col_3": 2.0},
    {"col_1": "3", "col_2": 3, "col_3": 3.0},
]
UpperCAmelCase__				   =		[
    {"col_1": "4", "col_2": 4, "col_3": 4.0},
    {"col_1": "5", "col_2": 5, "col_3": 5.0},
]
UpperCAmelCase__				   =		{
    "col_1": ["0", "1", "2", "3"],
    "col_2": [0, 1, 2, 3],
    "col_3": [0.0, 1.0, 2.0, 3.0],
}

UpperCAmelCase__				   =		[
    {"col_3": 0.0, "col_1": "0", "col_2": 0},
    {"col_3": 1.0, "col_1": "1", "col_2": 1},
]

UpperCAmelCase__				   =		[
    {"col_1": "s0", "col_2": 0, "col_3": 0.0},
    {"col_1": "s1", "col_2": 1, "col_3": 1.0},
    {"col_1": "s2", "col_2": 2, "col_3": 2.0},
    {"col_1": "s3", "col_2": 3, "col_3": 3.0},
]
@pytest.fixture(scope='''session''' )
def 						_a    (      )							->			Tuple:
 return DATA_DICT_OF_LISTS
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any] )							->			Optional[Any]:
 a		  =      datasets.Dataset.from_dict(a )
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.arrow''' )
 dataset.map(cache_file_name=a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Tuple )							->			Optional[Any]:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.sqlite''' )
 with contextlib.closing(sqlitea.connect(a ) ) as con:
  a		  =      con.cursor()
  cur.execute('''CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)''' )
  for item in DATA:
   cur.execute('''INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'''	,							tuple(item.values() ) )
  con.commit()
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any] )							->			Union[str, Any]:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.csv''' )
 with open(a	,							'''w'''	,							newline='''''' ) as f:
  a		  =      csv.DictWriter(a	,							fieldnames=['''col_1''', '''col_2''', '''col_3'''] )
  writer.writeheader()
  for item in DATA:
   writer.writerow(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any] )							->			str:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset2.csv''' )
 with open(a	,							'''w'''	,							newline='''''' ) as f:
  a		  =      csv.DictWriter(a	,							fieldnames=['''col_1''', '''col_2''', '''col_3'''] )
  writer.writeheader()
  for item in DATA:
   writer.writerow(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Optional[int]	,							a :Union[str, Any] )							->			List[Any]:
 import bza

 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.csv.bz2'''
 with open(a	,							'''rb''' ) as f:
  a		  =      f.read()
 # data = bytes(FILE_CONTENT, "utf-8")
 with bza.open(a	,							'''wb''' ) as f:
  f.write(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Dict	,							a :Optional[Any]	,							a :Optional[int] )							->			int:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.csv.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename(a ) )
  f.write(a	,							arcname=os.path.basename(a ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any]	,							a :List[str]	,							a :List[str] )							->			Tuple:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.csv.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename(csv_path.replace('''.csv'''	,							'''.CSV''' ) ) )
  f.write(a	,							arcname=os.path.basename(csva_path.replace('''.csv'''	,							'''.CSV''' ) ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any	,							a :Union[str, Any]	,							a :str )							->			List[Any]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset_with_dir.csv.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.join('''main_dir'''	,							os.path.basename(a ) ) )
  f.write(a	,							arcname=os.path.join('''main_dir'''	,							os.path.basename(a ) ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any )							->			Any:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.parquet''' )
 a		  =      pa.schema(
     {
         '''col_1''': pa.string(),
         '''col_2''': pa.intaa(),
         '''col_3''': pa.floataa(),
     } )
 with open(a	,							'''wb''' ) as f:
  a		  =      pq.ParquetWriter(a	,							schema=a )
  a		  =      pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(a ) )] for k in DATA[0]}	,							schema=a )
  writer.write_table(a )
  writer.close()
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[Any] )							->			Any:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.json''' )
 a		  =      {'''data''': DATA}
 with open(a	,							'''w''' ) as f:
  json.dump(a	,							a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Optional[Any] )							->			List[Any]:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.json''' )
 a		  =      {'''data''': DATA_DICT_OF_LISTS}
 with open(a	,							'''w''' ) as f:
  json.dump(a	,							a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[Any] )							->			int:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.jsonl''' )
 with open(a	,							'''w''' ) as f:
  for item in DATA:
   f.write(json.dumps(a ) + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Optional[int] )							->			Optional[Any]:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset2.jsonl''' )
 with open(a	,							'''w''' ) as f:
  for item in DATA:
   f.write(json.dumps(a ) + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any )							->			Dict:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset_312.jsonl''' )
 with open(a	,							'''w''' ) as f:
  for item in DATA_312:
   f.write(json.dumps(a ) + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any )							->			List[str]:
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset-str.jsonl''' )
 with open(a	,							'''w''' ) as f:
  for item in DATA_STR:
   f.write(json.dumps(a ) + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any]	,							a :int )							->			str:
 import gzip

 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.txt.gz''' )
 with open(a	,							'''rb''' ) as orig_file:
  with gzip.open(a	,							'''wb''' ) as zipped_file:
   zipped_file.writelines(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any	,							a :Union[str, Any] )							->			List[Any]:
 import gzip

 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.jsonl.gz''' )
 with open(a	,							'''rb''' ) as orig_file:
  with gzip.open(a	,							'''wb''' ) as zipped_file:
   zipped_file.writelines(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :int	,							a :Optional[Any]	,							a :List[Any] )							->			Union[str, Any]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.jsonl.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename(a ) )
  f.write(a	,							arcname=os.path.basename(a ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any	,							a :Dict	,							a :str	,							a :Optional[Any] )							->			str:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset_nested.jsonl.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.join('''nested'''	,							os.path.basename(a ) ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[str]	,							a :Optional[int]	,							a :Tuple )							->			int:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset_with_dir.jsonl.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.join('''main_dir'''	,							os.path.basename(a ) ) )
  f.write(a	,							arcname=os.path.join('''main_dir'''	,							os.path.basename(a ) ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Optional[int]	,							a :int	,							a :Optional[Any] )							->			int:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.jsonl.tar'''
 with tarfile.TarFile(a	,							'''w''' ) as f:
  f.add(a	,							arcname=os.path.basename(a ) )
  f.add(a	,							arcname=os.path.basename(a ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[str]	,							a :List[str]	,							a :str	,							a :Tuple )							->			Union[str, Any]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset_nested.jsonl.tar'''
 with tarfile.TarFile(a	,							'''w''' ) as f:
  f.add(a	,							arcname=os.path.join('''nested'''	,							os.path.basename(a ) ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[Any] )							->			Tuple:
 a		  =      ['''0''', '''1''', '''2''', '''3''']
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset.txt''' )
 with open(a	,							'''w''' ) as f:
  for item in data:
   f.write(item + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any )							->			List[Any]:
 a		  =      ['''0''', '''1''', '''2''', '''3''']
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset2.txt''' )
 with open(a	,							'''w''' ) as f:
  for item in data:
   f.write(item + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any] )							->			List[str]:
 a		  =      ['''0''', '''1''', '''2''', '''3''']
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.abc'''
 with open(a	,							'''w''' ) as f:
  for item in data:
   f.write(item + '''\n''' )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Optional[Any]	,							a :List[str]	,							a :int )							->			List[Any]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.text.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename(a ) )
  f.write(a	,							arcname=os.path.basename(a ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :List[str]	,							a :int	,							a :Dict )							->			int:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset_with_dir.text.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.join('''main_dir'''	,							os.path.basename(a ) ) )
  f.write(a	,							arcname=os.path.join('''main_dir'''	,							os.path.basename(a ) ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Any	,							a :Tuple	,							a :List[str] )							->			Optional[Any]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.ext.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename('''unsupported.ext''' ) )
  f.write(a	,							arcname=os.path.basename('''unsupported_2.ext''' ) )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      a :Union[str, Any] )							->			Dict:
 a		  =      '''\n'''.join(['''First''', '''Second\u2029with Unicode new line''', '''Third'''] )
 a		  =      str(tmp_path_factory.mktemp('''data''' ) / '''dataset_with_unicode_new_lines.txt''' )
 with open(a	,							'''w'''	,							encoding='''utf-8''' ) as f:
  f.write(a )
 return path
@pytest.fixture(scope='''session''' )
def 						_a    (      )							->			str:
 return os.path.join('''tests'''	,							'''features'''	,							'''data'''	,							'''test_image_rgb.jpg''' )
@pytest.fixture(scope='''session''' )
def 						_a    (      )							->			Dict:
 return os.path.join('''tests'''	,							'''features'''	,							'''data'''	,							'''test_audio_44100.wav''' )
@pytest.fixture(scope='''session''' )
def 						_a    (      a :int	,							a :int )							->			Optional[int]:
 a		  =      tmp_path_factory.mktemp('''data''' ) / '''dataset.img.zip'''
 with zipfile.ZipFile(a	,							'''w''' ) as f:
  f.write(a	,							arcname=os.path.basename(a ) )
  f.write(a	,							arcname=os.path.basename(a ).replace('''.jpg'''	,							'''2.jpg''' ) )
 return path

@pytest.fixture(scope='''session''' )
def 						_a    (      a :Dict )							->			Dict:
 a		  =      tmp_path_factory.mktemp('''data_dir''' )

 (data_dir / "subdir").mkdir()
 with open(data_dir / '''subdir''' / '''train.txt'''	,							'''w''' ) as f:
  f.write('''foo\n''' * 10 )
 with open(data_dir / '''subdir''' / '''test.txt'''	,							'''w''' ) as f:
  f.write('''bar\n''' * 10 )
 # hidden file
 with open(data_dir / '''subdir''' / '''.test.txt'''	,							'''w''' ) as f:
  f.write('''bar\n''' * 10 )

 # hidden directory
 (data_dir / ".subdir").mkdir()
 with open(data_dir / '''.subdir''' / '''train.txt'''	,							'''w''' ) as f:
  f.write('''foo\n''' * 10 )
 with open(data_dir / '''.subdir''' / '''test.txt'''	,							'''w''' ) as f:
  f.write('''bar\n''' * 10 )

 return data_dir










import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokenizer

from diffusers import HeunDiscreteScheduler, PriorTransformer, ShapEPipeline
from diffusers.pipelines.shap_e import ShapERenderer
from diffusers.utils import load_numpy, slow
from diffusers.utils.testing_utils import require_torch_gpu, torch_device

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference






class 		lowercase_					(	lowercase ,  unittest.TestCase   ):






      '''simple docstring'''




      __snake_case       =  ShapEPipeline
      __snake_case       =  ['''prompt''']
      __snake_case       =  ['''prompt''']
      __snake_case       =  [
          '''num_images_per_prompt''',
          '''num_inference_steps''',
          '''generator''',
          '''latents''',
          '''guidance_scale''',
          '''frame_size''',
          '''output_type''',
          '''return_dict''',
      ]
      __snake_case       =  False







      @property
      def       __lowerCAmelCase					(      self      :						Union[str, Any]  )    ->Union[str, Any]:




       """simple docstring"""


       return 32







      @property
      def       __lowerCAmelCase					(      self      :						Optional[Any]  )    ->List[str]:




       """simple docstring"""


       return 32







      @property
      def       __lowerCAmelCase					(      self      :						Any  )    ->Tuple:




       """simple docstring"""


       return self.time_input_dim * 4







      @property
      def       __lowerCAmelCase					(      self      :						Tuple  )    ->Optional[Any]:




       """simple docstring"""


       return 8







      @property
      def       __lowerCAmelCase					(      self      :						Tuple  )    ->str:




       """simple docstring"""


       a		  =      CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''  )
       return tokenizer







      @property
      def       __lowerCAmelCase					(      self      :						Union[str, Any]  )    ->List[Any]:




       """simple docstring"""


       torch.manual_seed(0  )
       a		  =      CLIPTextConfig(
           bos_token_id=0 ,					eos_token_id=2 ,					hidden_size=self.text_embedder_hidden_size ,					projection_dim=self.text_embedder_hidden_size ,					intermediate_size=37 ,					layer_norm_eps=1e-0_5 ,					num_attention_heads=4 ,					num_hidden_layers=5 ,					pad_token_id=1 ,					vocab_size=1_000 ,					)
       return CLIPTextModelWithProjection(__UpperCAmelCase  )







      @property
      def       __lowerCAmelCase					(      self      :						Dict  )    ->Union[str, Any]:




       """simple docstring"""


       torch.manual_seed(0  )

       a		  =      {
           '''num_attention_heads''': 2,
           '''attention_head_dim''': 16,
           '''embedding_dim''': self.time_input_dim,
           '''num_embeddings''': 32,
           '''embedding_proj_dim''': self.text_embedder_hidden_size,
           '''time_embed_dim''': self.time_embed_dim,
           '''num_layers''': 1,
           '''clip_embed_dim''': self.time_input_dim * 2,
           '''additional_embeddings''': 0,
           '''time_embed_act_fn''': '''gelu''',
           '''norm_in_type''': '''layer''',
           '''encoder_hid_proj_type''': None,
           '''added_emb_type''': None,
       }

       a		  =      PriorTransformer(**__UpperCAmelCase  )
       return model







      @property
      def       __lowerCAmelCase					(      self      :						List[Any]  )    ->List[str]:




       """simple docstring"""


       torch.manual_seed(0  )

       a		  =      {
           '''param_shapes''': (
               (self.renderer_dim, 93),
               (self.renderer_dim, 8),
               (self.renderer_dim, 8),
               (self.renderer_dim, 8),
           ),
           '''d_latent''': self.time_input_dim,
           '''d_hidden''': self.renderer_dim,
           '''n_output''': 12,
           '''background''': (
               0.1,
               0.1,
               0.1,
           ),
       }
       a		  =      ShapERenderer(**__UpperCAmelCase  )
       return model







      def       __lowerCAmelCase					(      self      :						List[Any]  )    ->Any:




       """simple docstring"""


       a		  =      self.dummy_prior
       a		  =      self.dummy_text_encoder
       a		  =      self.dummy_tokenizer
       a		  =      self.dummy_renderer

       a		  =      HeunDiscreteScheduler(
           beta_schedule='''exp''' ,					num_train_timesteps=1_024 ,					prediction_type='''sample''' ,					use_karras_sigmas=__UpperCAmelCase ,					clip_sample=__UpperCAmelCase ,					clip_sample_range=1.0 ,					)
       a		  =      {
           '''prior''': prior,
           '''text_encoder''': text_encoder,
           '''tokenizer''': tokenizer,
           '''renderer''': renderer,
           '''scheduler''': scheduler,
       }

       return components







      def       __lowerCAmelCase					(      self      :						Tuple ,					__UpperCAmelCase      :						Optional[Any] ,					__UpperCAmelCase      :						str=0  )    ->Optional[int]:




       """simple docstring"""


       if str(__UpperCAmelCase  ).startswith('''mps'''  ):
        a		  =      torch.manual_seed(__UpperCAmelCase  )
       else:
        a		  =      torch.Generator(device=__UpperCAmelCase  ).manual_seed(__UpperCAmelCase  )
       a		  =      {
           '''prompt''': '''horse''',
           '''generator''': generator,
           '''num_inference_steps''': 1,
           '''frame_size''': 32,
           '''output_type''': '''np''',
       }
       return inputs







      def       __lowerCAmelCase					(      self      :						Dict  )    ->Optional[int]:




       """simple docstring"""


       a		  =      '''cpu'''

       a		  =      self.get_dummy_components()

       a		  =      self.pipeline_class(**__UpperCAmelCase  )
       a		  =      pipe.to(__UpperCAmelCase  )

       pipe.set_progress_bar_config(disable=__UpperCAmelCase  )

       a		  =      pipe(**self.get_dummy_inputs(__UpperCAmelCase  )  )
       a		  =      output.images[0]
       a		  =      image[0, -3:, -3:, -1]

       assert image.shape == (20, 32, 32, 3)

       a		  =      np.array(
           [
               0.00039216,
               0.00039216,
               0.00039216,
               0.00039216,
               0.00039216,
               0.00039216,
               0.00039216,
               0.00039216,
               0.00039216,
           ]  )

       assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2







      def       __lowerCAmelCase					(      self      :						Dict  )    ->Optional[Any]:




       """simple docstring"""


       self._test_inference_batch_consistent(batch_sizes=[1, 2]  )







      def       __lowerCAmelCase					(      self      :						Optional[Any]  )    ->Tuple:




       """simple docstring"""


       a		  =      torch_device == '''cpu'''
       a		  =      True

       self._test_inference_batch_single_identical(
           batch_size=2 ,					test_max_difference=__UpperCAmelCase ,					relax_max_difference=__UpperCAmelCase ,					)







      def       __lowerCAmelCase					(      self      :						str  )    ->Optional[int]:




       """simple docstring"""


       a		  =      self.get_dummy_components()
       a		  =      self.pipeline_class(**__UpperCAmelCase  )
       a		  =      pipe.to(__UpperCAmelCase  )
       pipe.set_progress_bar_config(disable=__UpperCAmelCase  )

       a		  =      1
       a		  =      2

       a		  =      self.get_dummy_inputs(__UpperCAmelCase  )

       for key in inputs.keys():
        if key in self.batch_params:
         a		  =      batch_size * [inputs[key]]

       a		  =      pipe(**__UpperCAmelCase ,					num_images_per_prompt=__UpperCAmelCase  )[0]

       assert images.shape[0] == batch_size * num_images_per_prompt






@slow
@require_torch_gpu
class 		lowercase_					(	unittest.TestCase   ):






      '''simple docstring'''




      def       __lowerCAmelCase					(      self      :						int  )    ->Any:




       """simple docstring"""


       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()







      def       __lowerCAmelCase					(      self      :						List[Any]  )    ->Union[str, Any]:




       """simple docstring"""


       a		  =      load_numpy(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
           '''/shap_e/test_shap_e_np_out.npy'''  )
       a		  =      ShapEPipeline.from_pretrained('''openai/shap-e'''  )
       a		  =      pipe.to(__UpperCAmelCase  )
       pipe.set_progress_bar_config(disable=__UpperCAmelCase  )

       a		  =      torch.Generator(device=__UpperCAmelCase  ).manual_seed(0  )

       a		  =      pipe(
           '''a shark''' ,					generator=__UpperCAmelCase ,					guidance_scale=15.0 ,					num_inference_steps=64 ,					frame_size=64 ,					output_type='''np''' ,					).images[0]

       assert images.shape == (20, 64, 64, 3)

       assert_mean_pixel_difference(__UpperCAmelCase ,					__UpperCAmelCase  )


