

# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
						import torch



class   __lowercase    (			TensorFormatter[Mapping, '''torch.Tensor''', Mapping]     ):




			"""simple docstring"""







			def __init__(			self  :					Dict       ,						lowerCAmelCase__  :					int=None       ,						**lowerCAmelCase__  :					Tuple):
									super().__init__(features=lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_:			str  		=	torch_tensor_kwargs
									import torch  # noqa import torch at initialization



			def 	_SCREAMING_SNAKE_CASE      (			self  :					int       ,						lowerCAmelCase__  :					Optional[int]):
									import torch

									if isinstance(lowerCAmelCase__       ,						lowerCAmelCase__) and column:
															if all(
															    isinstance(lowerCAmelCase__       ,						torch.Tensor) and x.shape == column[0].shape and x.dtype == column[0].dtype
															    for x in column):
																					return torch.stack(lowerCAmelCase__)
									return column



			def 	_SCREAMING_SNAKE_CASE      (			self  :					int       ,						lowerCAmelCase__  :					List[str]):
									import torch

									if isinstance(lowerCAmelCase__       ,						(str, bytes, type(lowerCAmelCase__))):
															return value
									elif isinstance(lowerCAmelCase__       ,						(np.character, np.ndarray)) and np.issubdtype(value.dtype       ,						np.character):
															return value.tolist()

									SCREAMING_SNAKE_CASE_:			Dict  		=	{}

									if isinstance(lowerCAmelCase__       ,						(np.number, np.ndarray)) and np.issubdtype(value.dtype       ,						np.integer):
															SCREAMING_SNAKE_CASE_:			List[Any]  		=	{"dtype": torch.intaa}
									elif isinstance(lowerCAmelCase__       ,						(np.number, np.ndarray)) and np.issubdtype(value.dtype       ,						np.floating):
															SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	{"dtype": torch.floataa}
									elif config.PIL_AVAILABLE and "PIL" in sys.modules:
															import PIL.Image

															if isinstance(lowerCAmelCase__       ,						PIL.Image.Image):
																					SCREAMING_SNAKE_CASE_:			Any  		=	np.asarray(lowerCAmelCase__)
									return torch.tensor(lowerCAmelCase__       ,						**{**default_dtype, **self.torch_tensor_kwargs})



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple       ,						lowerCAmelCase__  :					List[Any]):
									import torch

									# support for torch, tf, jax etc.
									if hasattr(lowerCAmelCase__       ,						"__array__") and not isinstance(lowerCAmelCase__       ,						torch.Tensor):
															SCREAMING_SNAKE_CASE_:			List[Any]  		=	data_struct.__array__()
									# support for nested types like struct of list of struct
									if isinstance(lowerCAmelCase__       ,						np.ndarray):
															if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
																					return self._consolidate([self.recursive_tensorize(lowerCAmelCase__) for substruct in data_struct])
									elif isinstance(lowerCAmelCase__       ,						(list, tuple)):
															return self._consolidate([self.recursive_tensorize(lowerCAmelCase__) for substruct in data_struct])
									return self._tensorize(lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple       ,						lowerCAmelCase__  :					dict):
									return map_nested(self._recursive_tensorize       ,						lowerCAmelCase__       ,						map_list=lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					str       ,						lowerCAmelCase__  :					pa.Table):
									SCREAMING_SNAKE_CASE_:			Any  		=	self.numpy_arrow_extractor().extract_row(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	self.python_features_decoder.decode_row(lowerCAmelCase__)
									return self.recursive_tensorize(lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple       ,						lowerCAmelCase__  :					pa.Table):
									SCREAMING_SNAKE_CASE_:			Any  		=	self.numpy_arrow_extractor().extract_column(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	self.python_features_decoder.decode_column(lowerCAmelCase__       ,						pa_table.column_names[0])
									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	self.recursive_tensorize(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_:			str  		=	self._consolidate(lowerCAmelCase__)
									return column




			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[Any]       ,						lowerCAmelCase__  :					pa.Table):
									SCREAMING_SNAKE_CASE_:			Tuple  		=	self.numpy_arrow_extractor().extract_batch(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_:			List[str]  		=	self.python_features_decoder.decode_batch(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_:			int  		=	self.recursive_tensorize(lowerCAmelCase__)
									for column_name in batch:
															SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	self._consolidate(batch[column_name])
									return batch









import torch

from diffusers import StableDiffusionPipeline


lowerCAmelCase							:  Any            =						"""path-to-your-trained-model"""
lowerCAmelCase							:  int            =						StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.floataa).to("""cuda""")

lowerCAmelCase							:  Union[str, Any]            =						"""A photo of sks dog in a bucket"""
lowerCAmelCase							:  Any            =						pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]

image.save("""dog-bucket.png""")






