


from logging import getLogger
from typing import Any, Callable, List, Optional, Union

import numpy as np
import PIL
import torch

from ...schedulers import DDPMScheduler
from ..onnx_utils import ORT_TO_NP_TYPE, OnnxRuntimeModel
from ..pipeline_utils import ImagePipelineOutput
from . import StableDiffusionUpscalePipeline


UpperCAmelCase			=    getLogger(__name__)


UpperCAmelCase			=    4
UpperCAmelCase			=    7

UpperCAmelCase			=    {
    """float16""": torch.floataa,
    """float32""": torch.floataa,
}






def        __lowerCAmelCase    (SCREAMING_SNAKE_CASE					)->  Dict:




      """simple docstring"""

      if isinstance(SCREAMING_SNAKE_CASE					,					torch.Tensor					):
            return image
      elif isinstance(SCREAMING_SNAKE_CASE					,					PIL.Image.Image					):
            snake_case_       =      [image]

      if isinstance(image[0]					,					PIL.Image.Image					):
            snake_case_       =      image[0].size
            snake_case_       =      (x - x % 64 for x in (w, h))  # resize to integer multiple of 32

            snake_case_       =      [np.array(i.resize((w, h)					)					)[None, :] for i in image]
            snake_case_       =      np.concatenate(SCREAMING_SNAKE_CASE					,					axis=0					)
            snake_case_       =      np.array(SCREAMING_SNAKE_CASE					).astype(np.floataa					) / 2_5_5.0
            snake_case_       =      image.transpose(0					,					3					,					1					,					2					)
            snake_case_       =      2.0 * image - 1.0
            snake_case_       =      torch.from_numpy(SCREAMING_SNAKE_CASE					)
      elif isinstance(image[0]					,					torch.Tensor					):
            snake_case_       =      torch.cat(SCREAMING_SNAKE_CASE					,					dim=0					)

      return image







class lowerCAmelCase_						( lowerCamelCase__       ):

 '''simple docstring'''

 def __init__(	self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase = 3_50		,      ):
       super().__init__(
           vae=UpperCAmelCase_		,      text_encoder=UpperCAmelCase_		,      tokenizer=UpperCAmelCase_		,      unet=UpperCAmelCase_		,      low_res_scheduler=UpperCAmelCase_		,      scheduler=UpperCAmelCase_		,      safety_checker=UpperCAmelCase_		,      feature_extractor=UpperCAmelCase_		,      watermarker=UpperCAmelCase_		,      max_noise_level=UpperCAmelCase_		,      )



 def __call__(	self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase = 75		,      _UpperCAmelCase = 9.0		,      _UpperCAmelCase = 20		,      _UpperCAmelCase = None		,      _UpperCAmelCase = 1		,      _UpperCAmelCase = 0.0		,      _UpperCAmelCase = None		,      _UpperCAmelCase = None		,      _UpperCAmelCase = None		,      _UpperCAmelCase = None		,      _UpperCAmelCase = "pil"		,      _UpperCAmelCase = True		,      _UpperCAmelCase = None		,      _UpperCAmelCase = 1		,      ):
       self.check_inputs(UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_					)

       # 2. Define call parameters
       if prompt is not None and isinstance(UpperCAmelCase_		,      UpperCAmelCase_					):
             snake_case_       =      1
       elif prompt is not None and isinstance(UpperCAmelCase_		,      UpperCAmelCase_					):
             snake_case_       =      len(UpperCAmelCase_					)
       else:
             snake_case_       =      prompt_embeds.shape[0]

       snake_case_       =      self._execution_device
       # here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
       # of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
       # corresponds to doing no classifier free guidance.
       snake_case_       =      guidance_scale > 1.0

       # 3. Encode input prompt
       snake_case_       =      self._encode_prompt(
           UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      prompt_embeds=UpperCAmelCase_		,      negative_prompt_embeds=UpperCAmelCase_		,      )

       snake_case_       =      ORT_TO_PT_TYPE[str(text_embeddings.dtype					)]

       # 4. Preprocess image
       snake_case_       =      preprocess(UpperCAmelCase_					)
       snake_case_       =      image.cpu()

       # 5. set timesteps
       self.scheduler.set_timesteps(UpperCAmelCase_		,      device=UpperCAmelCase_					)
       snake_case_       =      self.scheduler.timesteps

       # 5. Add noise to image
       snake_case_       =      torch.tensor([noise_level]		,      dtype=torch.long		,      device=UpperCAmelCase_					)
       snake_case_       =      torch.randn(image.shape		,      generator=UpperCAmelCase_		,      device=UpperCAmelCase_		,      dtype=UpperCAmelCase_					)
       snake_case_       =      self.low_res_scheduler.add_noise(UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_					)

       snake_case_       =      2 if do_classifier_free_guidance else 1
       snake_case_       =      np.concatenate([image] * batch_multiplier * num_images_per_prompt					)
       snake_case_       =      np.concatenate([noise_level] * image.shape[0]					)

       # 6. Prepare latent variables
       snake_case_       =      image.shape[2:]
       snake_case_       =      self.prepare_latents(
           batch_size * num_images_per_prompt		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      )

       # 7. Check that sizes of image and latents match
       snake_case_       =      image.shape[1]
       if NUM_LATENT_CHANNELS + num_channels_image != NUM_UNET_INPUT_CHANNELS:
             raise ValueError(
                 '''Incorrect configuration settings! The config of `pipeline.unet` expects'''
                 F''' {NUM_UNET_INPUT_CHANNELS} but received `num_channels_latents`: {NUM_LATENT_CHANNELS} +'''
                 F''' `num_channels_image`: {num_channels_image} '''
                 F''' = {NUM_LATENT_CHANNELS+num_channels_image}. Please verify the config of'''
                 ''' `pipeline.unet` or your `image` input.'''					)

       # 8. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
       snake_case_       =      self.prepare_extra_step_kwargs(UpperCAmelCase_		,      UpperCAmelCase_					)

       snake_case_       =      next(
           (input.type for input in self.unet.model.get_inputs() if input.name == '''timestep''')		,      '''tensor(float)'''					)
       snake_case_       =      ORT_TO_NP_TYPE[timestep_dtype]

       # 9. Denoising loop
       snake_case_       =      len(UpperCAmelCase_					) - num_inference_steps * self.scheduler.order
       with self.progress_bar(total=UpperCAmelCase_					) as progress_bar:
             for i, t in enumerate(UpperCAmelCase_					):
                   # expand the latents if we are doing classifier free guidance
                   snake_case_       =      np.concatenate([latents] * 2					) if do_classifier_free_guidance else latents

                   # concat latents, mask, masked_image_latents in the channel dimension
                   snake_case_       =      self.scheduler.scale_model_input(UpperCAmelCase_		,      UpperCAmelCase_					)
                   snake_case_       =      np.concatenate([latent_model_input, image]		,      axis=1					)

                   # timestep to tensor
                   snake_case_       =      np.array([t]		,      dtype=UpperCAmelCase_					)

                   # predict the noise residual
                   snake_case_       =      self.unet(
                       sample=UpperCAmelCase_		,      timestep=UpperCAmelCase_		,      encoder_hidden_states=UpperCAmelCase_		,      class_labels=noise_level.astype(np.intaa					)		,      )[0]

                   # perform guidance
                   if do_classifier_free_guidance:
                         snake_case_       =      np.split(UpperCAmelCase_		,      2					)
                   snake_case_       =      noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)

                   # compute the previous noisy sample x_t -> x_t-1
                   snake_case_       =      self.scheduler.step(
                       torch.from_numpy(UpperCAmelCase_					)		,      UpperCAmelCase_		,      UpperCAmelCase_		,      **UpperCAmelCase_					).prev_sample

                   # call the callback, if provided
                   if i == len(UpperCAmelCase_					) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
                         progress_bar.update()
                         if callback is not None and i % callback_steps == 0:
                               callback(UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_					)

        # 10. Post-processing
       snake_case_       =      self.decode_latents(latents.float()					)

       # 11. Convert to PIL
       if output_type == "pil":
             snake_case_       =      self.numpy_to_pil(UpperCAmelCase_					)

       if not return_dict:
             return (image,)

       return ImagePipelineOutput(images=UpperCAmelCase_					)



 def 						UpperCamelCase__     (	self		,      _UpperCAmelCase					):
       snake_case_       =      1 / 0.08_333 * latents
       snake_case_       =      self.vae(latent_sample=UpperCAmelCase_					)[0]
       snake_case_       =      np.clip(image / 2 + 0.5		,      0		,      1					)
       snake_case_       =      image.transpose((0, 2, 3, 1)					)
       return image





 def 						UpperCamelCase__     (	self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase = None		,      _UpperCAmelCase = None		,      ):
       if prompt is not None and isinstance(UpperCAmelCase_		,      UpperCAmelCase_					):
             snake_case_       =      1
       elif prompt is not None and isinstance(UpperCAmelCase_		,      UpperCAmelCase_					):
             snake_case_       =      len(UpperCAmelCase_					)
       else:
             snake_case_       =      prompt_embeds.shape[0]

       if prompt_embeds is None:
             snake_case_       =      self.tokenizer(
                 UpperCAmelCase_		,      padding='''max_length'''		,      max_length=self.tokenizer.model_max_length		,      truncation=UpperCAmelCase_		,      return_tensors='''pt'''		,      )
             snake_case_       =      text_inputs.input_ids
             snake_case_       =      self.tokenizer(UpperCAmelCase_		,      padding='''longest'''		,      return_tensors='''pt'''					).input_ids

             if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(
                 UpperCAmelCase_		,      UpperCAmelCase_					):
                   snake_case_       =      self.tokenizer.batch_decode(
                       untruncated_ids[:, self.tokenizer.model_max_length - 1 : -1]					)
                   logger.warning(
                       '''The following part of your input was truncated because CLIP can only handle sequences up to'''
                       F''' {self.tokenizer.model_max_length} tokens: {removed_text}'''					)

             # no positional arguments to text_encoder
             snake_case_       =      self.text_encoder(
                 input_ids=text_input_ids.int().to(UpperCAmelCase_					)		,      )
             snake_case_       =      prompt_embeds[0]

       snake_case_       =      prompt_embeds.shape
       # duplicate text embeddings for each generation per prompt, using mps friendly method
       snake_case_       =      prompt_embeds.repeat(1		,      UpperCAmelCase_					)
       snake_case_       =      prompt_embeds.reshape(bs_embed * num_images_per_prompt		,      UpperCAmelCase_		,      -1					)

       # get unconditional embeddings for classifier free guidance
       if do_classifier_free_guidance and negative_prompt_embeds is None:
             snake_case_       =      42
             if negative_prompt is None:
                   snake_case_       =      [""] * batch_size
             elif type(UpperCAmelCase_					) is not type(UpperCAmelCase_					):
                   raise TypeError(
                       F'''`negative_prompt` should be the same type to `prompt`, but got {type(UpperCAmelCase_					)} !='''
                       F''' {type(UpperCAmelCase_					)}.'''					)
             elif isinstance(UpperCAmelCase_		,      UpperCAmelCase_					):
                   snake_case_       =      [negative_prompt]
             elif batch_size != len(UpperCAmelCase_					):
                   raise ValueError(
                       F'''`negative_prompt`: {negative_prompt} has batch size {len(UpperCAmelCase_					)}, but `prompt`:'''
                       F''' {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches'''
                       ''' the batch size of `prompt`.'''					)
             else:
                   snake_case_       =      negative_prompt

             snake_case_       =      text_input_ids.shape[-1]
             snake_case_       =      self.tokenizer(
                 UpperCAmelCase_		,      padding='''max_length'''		,      max_length=UpperCAmelCase_		,      truncation=UpperCAmelCase_		,      return_tensors='''pt'''		,      )

             # if hasattr(uncond_input, "attention_mask"):
             #     attention_mask = uncond_input.attention_mask.to(device)
             # else:
             #     attention_mask = None

             snake_case_       =      self.text_encoder(
                 input_ids=uncond_input.input_ids.int().to(UpperCAmelCase_					)		,      )
             snake_case_       =      uncond_embeddings[0]

       if do_classifier_free_guidance:
             snake_case_       =      uncond_embeddings.shape[1]
             # duplicate unconditional embeddings for each generation per prompt, using mps friendly method
             snake_case_       =      uncond_embeddings.repeat(1		,      UpperCAmelCase_					)
             snake_case_       =      uncond_embeddings.reshape(batch_size * num_images_per_prompt		,      UpperCAmelCase_		,      -1					)

             # For classifier free guidance, we need to do two forward passes.
             # Here we concatenate the unconditional and text embeddings into a single batch
             # to avoid doing two forward passes
             snake_case_       =      np.concatenate([uncond_embeddings, prompt_embeds]					)

       return prompt_embeds







import csv
import os

import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.csv import CsvDatasetReader, CsvDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases


def      lowerCamelCase__	(   lowercase  ,   lowercase ):

  """simple docstring"""






  assert isinstance(lowercase  ,   lowercase )
  assert dataset.num_rows == 4
  assert dataset.num_columns == 3
  assert dataset.column_names == ["col_1", "col_2", "col_3"]
  for feature, expected_dtype in expected_features.items():
    assert dataset.features[feature].dtype == expected_dtype


@pytest.mark.parametrize("keep_in_memory"  ,   [False, True] )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					Union[str, Any]		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Dict		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
    SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			CsvDatasetReader(lowercase  ,   cache_dir=lowercase  ,   keep_in_memory=lowercase ).read()
  _check_csv_dataset(lowercase  ,   lowercase )


@pytest.mark.parametrize(
    "features"  ,   [
        None,
        {"col_1": "string", "col_2": "int64", "col_3": "float64"},
        {"col_1": "string", "col_2": "string", "col_3": "string"},
        {"col_1": "int32", "col_2": "int32", "col_3": "int32"},
        {"col_1": "float32", "col_2": "float32", "col_3": "float32"},
    ]  ,   )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					Any		  =			tmp_path / "cache"
  # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  SCREAMING_SNAKE_CASE				:					Any		  =			features.copy() if features else default_expected_features
  SCREAMING_SNAKE_CASE				:					List[Any]		  =			(
      Features({feature: Value(lowercase ) for feature, dtype in features.items()} ) if features is not None else None
  )
  SCREAMING_SNAKE_CASE				:					Tuple		  =			CsvDatasetReader(lowercase  ,   features=lowercase  ,   cache_dir=lowercase ).read()
  _check_csv_dataset(lowercase  ,   lowercase )


@pytest.mark.parametrize("split"  ,   [None, NamedSplit("train" ), "train", "test"] )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					Dict		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Dict		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  SCREAMING_SNAKE_CASE				:					List[Any]		  =			CsvDatasetReader(lowercase  ,   cache_dir=lowercase  ,   split=lowercase ).read()
  _check_csv_dataset(lowercase  ,   lowercase )
  assert dataset.split == split if split else "train"


@pytest.mark.parametrize("path_type"  ,   [str, list] )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  if issubclass(lowercase  ,   lowercase ):
    SCREAMING_SNAKE_CASE				:					Tuple		  =			csv_path
  elif issubclass(lowercase  ,   lowercase ):
    SCREAMING_SNAKE_CASE				:					int		  =			[csv_path]
  SCREAMING_SNAKE_CASE				:					Any		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Optional[int]		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  SCREAMING_SNAKE_CASE				:					Tuple		  =			CsvDatasetReader(lowercase  ,   cache_dir=lowercase ).read()
  _check_csv_dataset(lowercase  ,   lowercase )


def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase=("train",) ):

  """simple docstring"""






  assert isinstance(lowercase  ,   lowercase )
  for split in splits:
    SCREAMING_SNAKE_CASE				:					str		  =			dataset_dict[split]
    assert dataset.num_rows == 4
    assert dataset.num_columns == 3
    assert dataset.column_names == ["col_1", "col_2", "col_3"]
    for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype


@pytest.mark.parametrize("keep_in_memory"  ,   [False, True] )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					Union[str, Any]		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Union[str, Any]		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
    SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			CsvDatasetReader({"train": csv_path}  ,   cache_dir=lowercase  ,   keep_in_memory=lowercase ).read()
  _check_csv_datasetdict(lowercase  ,   lowercase )


@pytest.mark.parametrize(
    "features"  ,   [
        None,
        {"col_1": "string", "col_2": "int64", "col_3": "float64"},
        {"col_1": "string", "col_2": "string", "col_3": "string"},
        {"col_1": "int32", "col_2": "int32", "col_3": "int32"},
        {"col_1": "float32", "col_2": "float32", "col_3": "float32"},
    ]  ,   )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					int		  =			tmp_path / "cache"
  # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
  SCREAMING_SNAKE_CASE				:					Any		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			features.copy() if features else default_expected_features
  SCREAMING_SNAKE_CASE				:					List[Any]		  =			(
      Features({feature: Value(lowercase ) for feature, dtype in features.items()} ) if features is not None else None
  )
  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			CsvDatasetReader({"train": csv_path}  ,   features=lowercase  ,   cache_dir=lowercase ).read()
  _check_csv_datasetdict(lowercase  ,   lowercase )


@pytest.mark.parametrize("split"  ,   [None, NamedSplit("train" ), "train", "test"] )
def      lowerCamelCase__	(   lowercase  ,   lowercase  ,   lowercase ):

  """simple docstring"""






  if split:
    SCREAMING_SNAKE_CASE				:					Dict		  =			{split: csv_path}
  else:
    SCREAMING_SNAKE_CASE				:					str		  =			{"train": csv_path, "test": csv_path}
  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Dict		  =			{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
  SCREAMING_SNAKE_CASE				:					Tuple		  =			CsvDatasetReader(lowercase  ,   cache_dir=lowercase ).read()
  _check_csv_datasetdict(lowercase  ,   lowercase  ,   splits=list(path.keys() ) )
  assert all(dataset[split].split == split for split in path.keys() )


def      lowerCamelCase__	(   lowercase ):

  """simple docstring"""






  with open(lowercase  ,   encoding="utf-8" ) as csvfile:
    yield from csv.reader(lowercase )


def      lowerCamelCase__	(   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					List[Any]		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Optional[int]		  =			os.path.join(lowercase  ,   "tmp.csv" )
  SCREAMING_SNAKE_CASE				:					Optional[int]		  =			CsvDatasetReader({"train": csv_path}  ,   cache_dir=lowercase ).read()
  CsvDatasetWriter(dataset["train"]  ,   lowercase  ,   num_proc=1 ).write()

  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			iter_csv_file(lowercase )
  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			iter_csv_file(lowercase )

  for rowa, rowa in zip(lowercase  ,   lowercase ):
    assert rowa == rowa


def      lowerCamelCase__	(   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					Union[str, Any]		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					List[Any]		  =			os.path.join(lowercase  ,   "tmp.csv" )
  SCREAMING_SNAKE_CASE				:					List[str]		  =			CsvDatasetReader({"train": csv_path}  ,   cache_dir=lowercase ).read()
  CsvDatasetWriter(dataset["train"]  ,   lowercase  ,   num_proc=2 ).write()

  SCREAMING_SNAKE_CASE				:					Dict		  =			iter_csv_file(lowercase )
  SCREAMING_SNAKE_CASE				:					Tuple		  =			iter_csv_file(lowercase )

  for rowa, rowa in zip(lowercase  ,   lowercase ):
    assert rowa == rowa


def      lowerCamelCase__	(   lowercase  ,   lowercase ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE				:					Optional[Any]		  =			tmp_path / "cache"
  SCREAMING_SNAKE_CASE				:					Union[str, Any]		  =			os.path.join(lowercase  ,   "tmp.csv" )
  SCREAMING_SNAKE_CASE				:					List[str]		  =			CsvDatasetReader({"train": csv_path}  ,   cache_dir=lowercase ).read()
  with pytest.raises(lowercase ):
    CsvDatasetWriter(dataset["train"]  ,   lowercase  ,   num_proc=0 )






