docstr: Initialize an Argilla Trainer.
  
  Args:
      name (str): the name of the dataset you want to load.
      framework (str):
          the framework to use for training. Currently, only "transformers", "setfit", and "spacy"
          are supported.
      lang (spacy.Language):
          the spaCy language model to use for training, just required when `framework="spacy"`.
          Defaults to None, but it will be set to `spacy.blank("en")` if not specified.
      model (str):
          name or path to the baseline model to be used. If not specified will set to a good default
          per framework, if applicable. Defaults to None.
      train_size (float):
          the size of the training set. If not specified, the entire dataset will be used for training,
          which may be an issue if `framework="spacy"` as it requires a validation set. Defaults to None.
      seed (int): the random seed to ensure reproducibility. Defaults to None.
      gpu_id (int):
          the GPU ID to use when training a SpaCy model. Defaults to -1, which means that the CPU
          will be used by default. GPU IDs start in 0, which stands for the default GPU in the system,
          if available.
      framework_kwargs (dict): additional arguments for the framework.
      **load_kwargs: arguments for the rg.load() function.
docstr_tok: ["Initialize","an","Argilla","Trainer",".","Args",":","name","(","str",")",":","the","name","of","the","dataset","you","want","to","load",".","framework","(","str",")",":","the","framework","to","use","for","training",".","Currently",",","only","``","transformers","''",",","``","setfit","''",",","and","``","spacy","''","are","supported",".","lang","(","spacy.Language",")",":","the","spaCy","language","model","to","use","for","training",",","just","required","when","`","framework=","''","spacy","''","`",".","Defaults","to","None",",","but","it","will","be","set","to","`","spacy.blank","(","``","en","''",")","`","if","not","specified",".","model","(","str",")",":","name","or","path","to","the","baseline","model","to","be","used",".","If","not","specified","will","set","to","a","good","default","per","framework",",","if","applicable",".","Defaults","to","None",".","train_size","(","float",")",":","the","size","of","the","training","set",".","If","not","specified",",","the","entire","dataset","will","be","used","for","training",",","which","may","be","an","issue","if","`","framework=","''","spacy","''","`","as","it","requires","a","validation","set",".","Defaults","to","None",".","seed","(","int",")",":","the","random","seed","to","ensure","reproducibility",".","Defaults","to","None",".","gpu_id","(","int",")",":","the","GPU","ID","to","use","when","training","a","SpaCy","model",".","Defaults","to","-1",",","which","means","that","the","CPU","will","be","used","by","default",".","GPU","IDs","start","in","0",",","which","stands","for","the","default","GPU","in","the","system",",","if","available",".","framework_kwargs","(","dict",")",":","additional","arguments","for","the","framework",".","*","*","load_kwargs",":","arguments","for","the","rg.load","(",")","function","."]
code: def __init__(
      self,
      name: str,
      framework: str,
      workspace: str = None,
      lang: Optional["spacy.Language"] = None,
      model: Optional[str] = None,
      train_size: Optional[float] = None,
      seed: Optional[int] = None,
      gpu_id: Optional[int] = -1,
      framework_kwargs: Optional[dict] = {},
      **load_kwargs: Optional[dict],
  ) -> None:
      """
      Initialize an Argilla Trainer.
  
      Args:
          name (str): the name of the dataset you want to load.
          framework (str):
              the framework to use for training. Currently, only "transformers", "setfit", and "spacy"
              are supported.
          lang (spacy.Language):
              the spaCy language model to use for training, just required when `framework="spacy"`.
              Defaults to None, but it will be set to `spacy.blank("en")` if not specified.
          model (str):
              name or path to the baseline model to be used. If not specified will set to a good default
              per framework, if applicable. Defaults to None.
          train_size (float):
              the size of the training set. If not specified, the entire dataset will be used for training,
              which may be an issue if `framework="spacy"` as it requires a validation set. Defaults to None.
          seed (int): the random seed to ensure reproducibility. Defaults to None.
          gpu_id (int):
              the GPU ID to use when training a SpaCy model. Defaults to -1, which means that the CPU
              will be used by default. GPU IDs start in 0, which stands for the default GPU in the system,
              if available.
          framework_kwargs (dict): additional arguments for the framework.
          **load_kwargs: arguments for the rg.load() function.
      """
      argilla = active_client()
  
      self._name = name
      self._workspace = workspace or argilla.get_workspace()
      self._multi_label = False
      self._split_applied = False
      self._train_size = train_size
      self._seed = seed  # split is used for train-test-split and should therefore be fixed
      self.model = model
  
      if train_size:
          self._split_applied = True
  
      _pytorch_fallback_env = "PYTORCH_ENABLE_MPS_FALLBACK"
      if _pytorch_fallback_env not in os.environ:
          os.environ[_pytorch_fallback_env] = "1"
          warnings.warn(
              f"{_pytorch_fallback_env} not set. Setting it to 1.",
              UserWarning,
              stacklevel=2,
          )
  
      self.rg_dataset_snapshot = argilla.load(
          name=self._name, limit=1, workspace=workspace
      )
      if not len(self.rg_dataset_snapshot) > 0:
          raise ValueError(f"Dataset {self._name} is empty")
  
      if isinstance(
          self.rg_dataset_snapshot, DatasetForTextClassification
      ):
          self._rg_dataset_type = DatasetForTextClassification
          self._multi_label = self.rg_dataset_snapshot[0].multi_label
      elif isinstance(
          self.rg_dataset_snapshot, DatasetForTokenClassification
      ):
          self._rg_dataset_type = DatasetForTokenClassification
      elif isinstance(self.rg_dataset_snapshot, DatasetForText2Text):
          self._rg_dataset_type = DatasetForText2Text
      else:
          raise NotImplementedError(
              f"Dataset type {type(self.rg_dataset_snapshot)} is not supported."
          )
  
      self.dataset_full = argilla.load(name=self._name, **load_kwargs)
  
      # settings for the dataset
      self._settings = load_dataset_settings(
          name=self._name, workspace=workspace
      )
      if self._rg_dataset_type in [
          DatasetForTextClassification,
          DatasetForTokenClassification,
      ]:
          if self._settings is None:
              self._settings = (
                  self.dataset_full._infer_settings_from_records()
              )
  
      framework = Framework(framework)
      if framework in [Framework.SPACY, Framework.SPACY_TRANSFORMERS]:
          import spacy
  
          self.dataset_full_prepared = (
              self.dataset_full.prepare_for_training(
                  framework=framework,
                  settings=self._settings,
                  train_size=self._train_size,
                  seed=self._seed,
                  lang=spacy.blank("en") if lang is None else lang,
              )
          )
      else:
          self.dataset_full_prepared = (
              self.dataset_full.prepare_for_training(
                  framework=framework,
                  settings=self._settings,
                  train_size=self._train_size,
                  seed=self._seed,
              )
          )
  
      if framework is Framework.SETFIT:
          from argilla.training.setfit import ArgillaSetFitTrainer
  
          self._trainer = ArgillaSetFitTrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
              model=self.model,
          )
      elif framework is Framework.TRANSFORMERS:
          from argilla.training.transformers import (
              ArgillaTransformersTrainer,
          )
  
          self._trainer = ArgillaTransformersTrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
              model=self.model,
          )
      elif framework is Framework.PEFT:
          from argilla.training.peft import ArgillaPeftTrainer
  
          self._trainer = ArgillaPeftTrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
              model=self.model,
          )
      elif framework is Framework.SPACY:
          from argilla.training.spacy import ArgillaSpaCyTrainer
  
          self._trainer = ArgillaSpaCyTrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              model=self.model,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
              gpu_id=gpu_id,
              **framework_kwargs,  # freeze_tok2vec
          )
      elif framework is Framework.SPACY_TRANSFORMERS:
          from argilla.training.spacy import (
              ArgillaSpaCyTransformersTrainer,
          )
  
          self._trainer = ArgillaSpaCyTransformersTrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              model=self.model,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
              gpu_id=gpu_id,
              **framework_kwargs,  # update_transformer
          )
      elif framework is Framework.OPENAI:
          from argilla.training.openai import ArgillaOpenAITrainer
  
          self._trainer = ArgillaOpenAITrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              model=self.model,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
          )
      elif framework is Framework.SPAN_MARKER:
          if self._rg_dataset_type is not DatasetForTokenClassification:
              raise NotImplementedError(
                  f"{Framework.SPAN_MARKER} only supports `TokenClassification` tasks."
              )
          from argilla.training.span_marker import (
              ArgillaSpanMarkerTrainer,
          )
  
          self._trainer = ArgillaSpanMarkerTrainer(
              name=self._name,
              workspace=self._workspace,
              record_class=self._rg_dataset_type._RECORD_TYPE,
              dataset=self.dataset_full_prepared,
              model=self.model,
              multi_label=self._multi_label,
              settings=self._settings,
              seed=self._seed,
          )
  
      self._logger.info(self)
      self._track_trainer_usage(
          framework=framework,
          task=self._rg_dataset_type._RECORD_TYPE.__name__,
      )
  
imports: import logging
  import os
  import warnings
  from abc import ABC, abstractmethod
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
  from argilla.client.datasets import DatasetForText2Text, DatasetForTextClassification, DatasetForTokenClassification
  from argilla.client.models import Framework, Text2TextRecord, TextClassificationRecord, TokenClassificationRecord
  from argilla.client.singleton import active_client
  from argilla.datasets import TextClassificationSettings, TokenClassificationSettings, load_dataset_settings
  from argilla.utils.telemetry import get_telemetry_client
label_desc: Use image node_id 1 to create a new ArgillaTrainer object from inherited base classes: object with example: obj = ArgillaTrainer(name, framework, workspace, lang, model, train_size, seed, gpu_id, framework_kwargs)