text
stringlengths
31
243k
type
stringclasses
1 value
start
int64
36
275k
end
int64
286
280k
depth
int64
0
1
filepath
stringlengths
85
188
parent_class
stringclasses
3 values
class_index
int64
0
10.8k
class TFSeq2SeqLMOutput(ModelOutput): """ Base class for sequence-to-sequence language models outputs. Args: loss (`tf.Tensor` of shape `(n,)`, *optional*, where n is the number of non-masked labels, returned when `labels` is provided): Language modeling loss. logits (`tf.Tensor...
class_definition
27,417
31,307
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
300
class TFNextSentencePredictorOutput(ModelOutput): """ Base class for outputs of models predicting if two sentences are consecutive or not. Args: loss (`tf.Tensor` of shape `(n,)`, *optional*, where n is the number of non-masked labels, returned when `next_sentence_label` is provided): N...
class_definition
31,321
32,892
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
301
class TFSequenceClassifierOutput(ModelOutput): """ Base class for outputs of sentence classification models. Args: loss (`tf.Tensor` of shape `(batch_size, )`, *optional*, returned when `labels` is provided): Classification (or regression if config.num_labels==1) loss. logits (`...
class_definition
32,906
34,390
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
302
class TFSeq2SeqSequenceClassifierOutput(ModelOutput): """ Base class for outputs of sequence-to-sequence sentence classification models. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `label` is provided): Classification (or regression if config.num_labels==1) loss. ...
class_definition
34,404
38,103
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
303
class TFSemanticSegmenterOutput(ModelOutput): """ Base class for outputs of semantic segmentation models. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Classification (or regression if config.num_labels==1) loss. logits (`tf.Tensor` of...
class_definition
38,117
40,004
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
304
class TFSemanticSegmenterOutputWithNoAttention(ModelOutput): """ Base class for outputs of semantic segmentation models that do not output attention scores. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Classification (or regression if config....
class_definition
40,018
41,508
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
305
class TFImageClassifierOutput(ModelOutput): """ Base class for outputs of image classification models. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Classification (or regression if config.num_labels==1) loss. logits (`tf.Tensor` of sh...
class_definition
41,522
43,002
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
306
class TFMultipleChoiceModelOutput(ModelOutput): """ Base class for outputs of multiple choice models. Args: loss (`tf.Tensor` of shape *(batch_size, )*, *optional*, returned when `labels` is provided): Classification loss. logits (`tf.Tensor` of shape `(batch_size, num_choices)`...
class_definition
43,016
44,505
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
307
class TFTokenClassifierOutput(ModelOutput): """ Base class for outputs of token classification models. Args: loss (`tf.Tensor` of shape `(n,)`, *optional*, where n is the number of unmasked labels, returned when `labels` is provided) : Classification loss. logits (`tf.Tensor` of...
class_definition
44,519
45,967
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
308
class TFQuestionAnsweringModelOutput(ModelOutput): """ Base class for outputs of question answering models. Args: loss (`tf.Tensor` of shape `(batch_size, )`, *optional*, returned when `start_positions` and `end_positions` are provided): Total span extraction loss is the sum of a Cross-...
class_definition
45,981
47,643
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
309
class TFSeq2SeqQuestionAnsweringModelOutput(ModelOutput): """ Base class for outputs of sequence-to-sequence question answering models. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Total span extraction loss is the sum of a Cross-Entropy for ...
class_definition
47,657
51,168
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
310
class TFSequenceClassifierOutputWithPast(ModelOutput): """ Base class for outputs of sentence classification models. Args: loss (`tf.Tensor` of shape `(batch_size, )`, *optional*, returned when `labels` is provided): Classification (or regression if config.num_labels==1) loss. l...
class_definition
51,182
53,206
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
311
class TFImageClassifierOutputWithNoAttention(ModelOutput): """ Base class for outputs of image classification models. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Classification (or regression if config.num_labels==1) loss. logits (`t...
class_definition
53,220
54,274
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
312
class TFMaskedImageModelingOutput(ModelOutput): """ Base class for outputs of masked image completion / in-painting models. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `bool_masked_pos` is provided): Reconstruction loss. reconstruction (`tf.Tensor` of shap...
class_definition
54,288
56,073
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/modeling_tf_outputs.py
null
313
class TensorFlowBenchmark(Benchmark): args: TensorFlowBenchmarkArguments configs: PretrainedConfig framework: str = "TensorFlow" @property def framework_version(self): return tf.__version__ def _inference_speed(self, model_name: str, batch_size: int, sequence_length: int) -> float: ...
class_definition
2,522
13,245
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_tf.py
null
314
class PyTorchBenchmark(Benchmark): args: PyTorchBenchmarkArguments configs: PretrainedConfig framework: str = "PyTorch" @property def framework_version(self): return torch.__version__ def _inference_speed(self, model_name: str, batch_size: int, sequence_length: int) -> float: _...
class_definition
1,365
10,746
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark.py
null
315
class PyTorchBenchmarkArguments(BenchmarkArguments): deprecated_args = [ "no_inference", "no_cuda", "no_tpu", "no_speed", "no_memory", "no_env_print", "no_multi_process", ] def __init__(self, **kwargs): """ This __init__ is there for l...
class_definition
1,120
4,049
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_args.py
null
316
class BenchmarkArguments: """ BenchMarkArguments are arguments we use in our benchmark scripts **which relate to the training loop itself**. Using `HfArgumentParser` we can turn this class into argparse arguments to be able to specify them on the command line. """ models: List[str] = list_fiel...
class_definition
1,002
6,498
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_args_utils.py
null
317
class Frame(NamedTuple): """ `Frame` is a NamedTuple used to gather the current frame state. `Frame` has the following fields: - 'filename' (string): Name of the file currently executed - 'module' (string): Name of the module currently executed - 'line_number' (int): Number of the line ...
class_definition
3,544
4,136
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
318
class UsedMemoryState(NamedTuple): """ `UsedMemoryState` are named tuples with the following fields: - 'frame': a `Frame` namedtuple (see below) storing information on the current tracing frame (current file, location in current file) - 'cpu_memory': CPU RSS memory state *before* exec...
class_definition
4,139
4,676
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
319
class Memory(NamedTuple): """ `Memory` NamedTuple have a single field `bytes` and you can get a human readable str of the number of mega bytes by calling `__repr__` - `byte` (integer): number of bytes, """ bytes: int def __repr__(self) -> str: return str(bytes_to_mega_bytes(se...
class_definition
4,679
5,009
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
320
class MemoryState(NamedTuple): """ `MemoryState` are namedtuples listing frame + CPU/GPU memory with the following fields: - `frame` (`Frame`): the current frame (see above) - `cpu`: CPU memory consumed at during the current frame as a `Memory` named tuple - `gpu`: GPU memory consumed a...
class_definition
5,012
5,563
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
321
class MemorySummary(NamedTuple): """ `MemorySummary` namedtuple otherwise with the fields: - `sequential`: a list of `MemoryState` namedtuple (see below) computed from the provided `memory_trace` by subtracting the memory after executing each line from the memory before executing said line. ...
class_definition
5,566
6,612
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
322
class MemoryMeasureProcess(Process): """ `MemoryMeasureProcess` inherits from `Process` and overwrites its `run()` method. Used to measure the memory usage of a process """ def __init__(self, process_id: int, child_connection: Connection, interval: float): ...
class_definition
8,480
9,622
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
323
class Benchmark(ABC): """ Benchmarks is a simple but feature-complete benchmarking script to compare memory and time performance of models in Transformers. """ args: BenchmarkArguments configs: PretrainedConfig framework: str def __init__(self, args: BenchmarkArguments = None, configs:...
class_definition
22,684
37,598
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_utils.py
null
324
class TensorFlowBenchmarkArguments(BenchmarkArguments): deprecated_args = [ "no_inference", "no_cuda", "no_tpu", "no_speed", "no_memory", "no_env_print", "no_multi_process", ] def __init__(self, **kwargs): """ This __init__ is there fo...
class_definition
976
4,734
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/benchmark/benchmark_args_tf.py
null
325
class SelectiveScanFn(torch.autograd.Function): @staticmethod def forward( ctx, u, delta, A, B, C, D=None, z=None, delta_bias=None, delta_softplus=False, return_last_state=False ): if u.stride(-1) != 1: u = u.contiguous() if delta.stride(-1) != 1: delta = delt...
class_definition
1,336
4,206
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/kernels/falcon_mamba/selective_scan_with_ln_interface.py
null
326
class MambaInnerFn(torch.autograd.Function): @staticmethod @custom_fwd def forward( ctx, xz, conv1d_weight, conv1d_bias, x_proj_weight, delta_proj_weight, out_proj_weight, out_proj_bias, A, B=None, C=None, D=None...
class_definition
7,500
18,893
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/kernels/falcon_mamba/selective_scan_with_ln_interface.py
null
327
class PatchingSpec: """ Data class that holds patching specifications. Args: o: Module / object where the op to patch is located name: Name of the op to monkey patch custom_op: Custom op that patches the original op orig_op: Original op that is being patched op_wrapp...
class_definition
1,543
2,149
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/onnx/config.py
null
328
class OnnxConfig(ABC): """ Base class for ONNX exportable model describing metadata on how to export the model through the ONNX format. """ default_fixed_batch = 2 default_fixed_sequence = 8 default_fixed_num_choices = 4 torch_onnx_minimum_version = version.parse("1.8") _tasks_to_common...
class_definition
2,152
18,850
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/onnx/config.py
null
329
class OnnxConfigWithPast(OnnxConfig, ABC): def __init__( self, config: "PretrainedConfig", task: str = "default", patching_specs: List[PatchingSpec] = None, use_past: bool = False, ): super().__init__(config, task=task, patching_specs=patching_specs) self....
class_definition
18,853
24,825
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/onnx/config.py
null
330
class OnnxSeq2SeqConfigWithPast(OnnxConfigWithPast): @property def outputs(self) -> Mapping[str, Mapping[int, str]]: common_outputs = super(OnnxConfigWithPast, self).outputs # Renaming the outputs axes properly. for name, axes_names in common_outputs.items(): sequence_name = ...
class_definition
24,828
32,555
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/onnx/config.py
null
331
class FeaturesManager: _TASKS_TO_AUTOMODELS = {} _TASKS_TO_TF_AUTOMODELS = {} if is_torch_available(): _TASKS_TO_AUTOMODELS = { "default": AutoModel, "masked-lm": AutoModelForMaskedLM, "causal-lm": AutoModelForCausalLM, "seq2seq-lm": AutoModelForSeq2Se...
class_definition
2,811
28,263
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/onnx/features.py
null
332
class ParameterFormat(Enum): Float = c_float @property def size(self) -> int: """ Number of byte required for this data type Returns: Integer > 0 """ return sizeof(self.value)
class_definition
822
1,063
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/onnx/utils.py
null
333
class ImageLoss(nn.Module): """ This class computes the losses for DetrForObjectDetection/DetrForSegmentation. The process happens in two steps: 1) we compute hungarian assignment between ground truth boxes and the outputs of the model 2) we supervise each pair of matched ground-truth / prediction (supe...
class_definition
3,155
12,632
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_for_object_detection.py
null
334
class HungarianMatcher(nn.Module): """ This class computes an assignment between the targets and the predictions of the network. For efficiency reasons, the targets don't include the no_object. Because of this, in general, there are more predictions than targets. In this case, we do a 1-to-1 matching o...
class_definition
12,719
16,676
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_for_object_detection.py
null
335
class NestedTensor: def __init__(self, tensors, mask: Optional[Tensor]): self.tensors = tensors self.mask = mask def to(self, device): cast_tensor = self.tensors.to(device) mask = self.mask if mask is not None: cast_mask = mask.to(device) else: ...
class_definition
19,545
20,062
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_for_object_detection.py
null
336
class DeformableDetrHungarianMatcher(HungarianMatcher): @torch.no_grad() def forward(self, outputs, targets): """ Differences: - out_prob = outputs["logits"].flatten(0, 1).sigmoid() instead of softmax - class_cost uses alpha and gamma """ batch_size, num_queries =...
class_definition
361
2,240
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_deformable_detr.py
null
337
class DeformableDetrImageLoss(ImageLoss): def __init__(self, matcher, num_classes, focal_alpha, losses): nn.Module.__init__(self) self.matcher = matcher self.num_classes = num_classes self.focal_alpha = focal_alpha self.losses = losses # removed logging parameter, which ...
class_definition
2,243
3,988
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_deformable_detr.py
null
338
class RTDetrHungarianMatcher(nn.Module): """This class computes an assignment between the targets and the predictions of the network For efficiency reasons, the targets don't include the no_object. Because of this, in general, there are more predictions than targets. In this case, we do a 1-to-1 matching o...
class_definition
1,110
5,300
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_rt_detr.py
null
339
class RTDetrLoss(nn.Module): """ This class computes the losses for RTDetr. The process happens in two steps: 1) we compute hungarian assignment between ground truth boxes and the outputs of the model 2) we supervise each pair of matched ground-truth / prediction (supervise class and box). Args: ...
class_definition
5,303
20,263
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/loss/loss_rt_detr.py
null
340
class CompressedTensorsHfQuantizer(HfQuantizer): """ Quantizer for the compressed_tensors package. Loads and restores models to quantized state with compressed_tensors """ requires_calibration = True required_packages = ["compressed_tensors"] def __init__(self, quantization_config: Compre...
class_definition
884
5,366
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_compressed_tensors.py
null
341
class FbgemmFp8HfQuantizer(HfQuantizer): """ FP8 quantization using fbgemm kernels """ requires_parameters_quantization = True requires_calibration = False required_packages = ["fbgemm-gpu", "accelerate"] def __init__(self, quantization_config, **kwargs): super().__init__(quantiza...
class_definition
1,055
8,141
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_fbgemm_fp8.py
null
342
class AwqQuantizer(HfQuantizer): """ 4-bit quantization for Activation-aware Weight Quantization(AWQ) (https://arxiv.org/abs/2306.00978) """ # AWQ requires data callibration - we support only inference requires_calibration = True required_packages = ["awq", "accelerate"] def __init__(self...
class_definition
1,040
6,901
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_awq.py
null
343
class Bnb4BitHfQuantizer(HfQuantizer): """ 4-bit quantization from bitsandbytes.py quantization method: before loading: converts transformer layers into Linear4bit during loading: load 16bit weight and pass to the layer object after: quantizes individual weights in Linear4bit into 4bit at the fi...
class_definition
1,246
16,330
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_bnb_4bit.py
null
344
class TorchAoHfQuantizer(HfQuantizer): """ Quantizer for torchao: https://github.com/pytorch/ao/ """ requires_parameters_quantization = True requires_calibration = False required_packages = ["torchao"] def __init__(self, quantization_config, **kwargs): super().__init__(quantization...
class_definition
2,144
10,119
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_torchao.py
null
345
class GptqHfQuantizer(HfQuantizer): """ Quantizer of the GPTQ method - for GPTQ the quantizer support calibration of the model through `auto_gptq` or `gptqmodel` package. Quantization is done under the hood for users if they load a non-prequantized model. """ requires_calibration = False requir...
class_definition
1,082
5,430
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_gptq.py
null
346
class QuantoHfQuantizer(HfQuantizer): """ Quantizer for the quanto library """ required_packages = ["quanto", "accelerate"] requires_parameters_quantization = True requires_calibration = False def __init__(self, quantization_config: QuantoConfig, **kwargs): super().__init__(quantiz...
class_definition
1,139
8,106
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_quanto.py
null
347
class EetqHfQuantizer(HfQuantizer): """ 8-bit quantization from EETQ quantization method: before loading: converts transformer layers into W8A16Linear during loading: load 16bit weight and pass to the layer object after: quantizes individual weights in Linear8bitLt into 8bit at first .cuda() cal...
class_definition
1,001
7,325
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_eetq.py
null
348
class BitNetHfQuantizer(HfQuantizer): """ 1.58-bit quantization from BitNet quantization method: Before loading: it converts the linear layers into BitLinear layers during loading. Checkout the paper introducing this method : https://arxiv.org/pdf/2402.17764 """ requires_parameters_quantizatio...
class_definition
923
4,301
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_bitnet.py
null
349
class AqlmHfQuantizer(HfQuantizer): """ Quantizer of the AQLM method. Enables the loading of prequantized models. """ requires_calibration = True required_packages = ["aqlm"] optimum_quantizer = None def __init__(self, quantization_config: QuantizationConfigMixin, **kwargs): super(...
class_definition
1,096
3,691
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_aqlm.py
null
350
class HqqHfQuantizer(HfQuantizer): """ HQQ quantizer base HF class. nn.Linear modules are first tagged with quant_config in _process_model_before_weight_loading(). The actual quantization and offloading to the GPU is done in check_quantized_param(). """ use_keep_in_fp32_modules = False requ...
class_definition
1,341
11,437
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_hqq.py
null
351
class VptqHfQuantizer(HfQuantizer): """ Quantizer of the VPTQ method. Enables the loading of prequantized models. """ requires_calibration = True required_packages = ["vptq"] def __init__(self, quantization_config: QuantizationConfigMixin, **kwargs): super().__init__(quantization_confi...
class_definition
996
3,719
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_vptq.py
null
352
class Bnb8BitHfQuantizer(HfQuantizer): """ 8-bit quantization from bitsandbytes quantization method: before loading: converts transformer layers into Linear8bitLt during loading: load 16bit weight and pass to the layer object after: quantizes individual weights in Linear8bitLt into 8bit at fitst...
class_definition
1,180
13,893
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_bnb_8bit.py
null
353
class HfQuantizer(ABC): """ Abstract class of the HuggingFace quantizer. Supports for now quantizing HF transformers models for inference and/or quantization. This class is used only for transformers.PreTrainedModel.from_pretrained and cannot be easily used outside the scope of that method yet. Att...
class_definition
932
10,501
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/base.py
null
354
class HiggsHfQuantizer(HfQuantizer): """ Quantizer of the HIGGS method. Enables the loading of prequantized models and in-flight quantization of full-precision models. """ requires_calibration = False requires_parameters_quantization = True required_packages = ["flute-kernel", "fast_hadamard_tr...
class_definition
1,583
9,576
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/quantizer_higgs.py
null
355
class AutoQuantizationConfig: """ The Auto-HF quantization config class that takes care of automatically dispatching to the correct quantization config given a quantization config stored in a dictionary. """ @classmethod def from_dict(cls, quantization_config_dict: Dict): quant_method =...
class_definition
2,727
4,829
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/auto.py
null
356
class AutoHfQuantizer: """ The Auto-HF quantizer class that takes care of automatically instantiating to the correct `HfQuantizer` given the `QuantizationConfig`. """ @classmethod def from_config(cls, quantization_config: Union[QuantizationConfigMixin, Dict], **kwargs): # Convert it to...
class_definition
4,832
8,014
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/quantizers/auto.py
null
357
class ImageQuestionAnsweringTool(PipelineTool): default_checkpoint = "dandelin/vilt-b32-finetuned-vqa" description = ( "This is a tool that answers a question about an image. It " "returns a text that is the answer to the question." ) name = "image_qa" pre_processor_class = AutoProce...
class_definition
835
2,003
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/image_question_answering.py
null
358
class Problem: """ A class regrouping all the information to solve a problem on which we will evaluate agents. Args: task (`str` ou `list[str]`): One or several descriptions of the task to perform. If a list, it should contain variations on the phrasing, but for the same tas...
class_definition
2,931
3,889
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/evaluate_agent.py
null
359
class ChatMessage: def __init__(self, role, content, metadata=None): self.role = role self.content = content self.metadata = metadata
class_definition
943
1,152
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/monitoring.py
null
360
class ChatMessage: def __init__(self, role, content, metadata=None): self.role = role self.content = content self.metadata = metadata
class_definition
2,409
2,618
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/monitoring.py
null
361
class Monitor: def __init__(self, tracked_llm_engine): self.step_durations = [] self.tracked_llm_engine = tracked_llm_engine if getattr(self.tracked_llm_engine, "last_input_token_count", "Not found") != "Not found": self.total_input_token_count = 0 self.total_output_t...
class_definition
3,628
4,683
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/monitoring.py
null
362
class Tool: """ A base class for the functions used by the agent. Subclass this and implement the `__call__` method as well as the following class attributes: - **description** (`str`) -- A short description of what your tool does, the inputs it expects and the output(s) it will return. For insta...
class_definition
3,043
23,689
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
null
363
class SpaceToolWrapper(Tool): def __init__( self, space_id: str, name: str, description: str, api_name: Optional[str] = None, token: Optional[str] = None, ): self.client = Client(space...
class_definition
18,293
21,668
1
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
Tool
364
class GradioToolWrapper(Tool): def __init__(self, _gradio_tool): self.name = _gradio_tool.name self.description = _gradio_tool.description self.output_type = "string" self._gradio_tool = _gradio_tool func_args = list(inspect.sig...
class_definition
21,919
22,502
1
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
Tool
365
class LangChainToolWrapper(Tool): def __init__(self, _langchain_tool): self.name = _langchain_tool.name.lower() self.description = _langchain_tool.description self.inputs = _langchain_tool.args.copy() for input_content in self.inputs.values(): ...
class_definition
22,692
23,636
1
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
Tool
366
class PipelineTool(Tool): """ A [`Tool`] tailored towards Transformer models. On top of the class attributes of the base class [`Tool`], you will need to specify: - **model_class** (`type`) -- The class to use to load the model in this tool. - **default_checkpoint** (`str`) -- The default checkpoin...
class_definition
24,882
31,025
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
null
367
class EndpointClient: def __init__(self, endpoint_url: str, token: Optional[str] = None): self.headers = { **build_hf_headers(token=token), "Content-Type": "application/json", } self.endpoint_url = endpoint_url @staticmethod def encode_image(image): _...
class_definition
35,377
36,954
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
null
368
class ToolCollection: """ Tool collections enable loading all Spaces from a collection in order to be added to the agent's toolbox. > [!NOTE] > Only Spaces will be fetched, so you can feel free to add models and datasets to your collection if you'd > like for this collection to showcase them. ...
class_definition
36,957
38,198
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
null
369
class SpecificTool(Tool): name = parameters["name"] description = parameters["description"] inputs = parameters["parameters"]["properties"] output_type = parameters["return"]["type"] @wraps(tool_function) def forward(self, *args, **kwargs): return tool_functi...
class_definition
38,825
39,164
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/tools.py
null
370
class MessageRole(str, Enum): USER = "user" ASSISTANT = "assistant" SYSTEM = "system" TOOL_CALL = "tool-call" TOOL_RESPONSE = "tool-response" @classmethod def roles(cls): return [r.value for r in cls]
class_definition
920
1,157
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/llm_engine.py
null
371
class HfEngine: def __init__(self, model_id: Optional[str] = None): self.last_input_token_count = None self.last_output_token_count = None if model_id is None: model_id = "HuggingFaceTB/SmolLM2-1.7B-Instruct" logger.warning(f"Using default model for token counting: '{...
class_definition
2,356
5,573
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/llm_engine.py
null
372
class HfApiEngine(HfEngine): """A class to interact with Hugging Face's Inference API for language model interaction. This engine allows you to communicate with Hugging Face's models using the Inference API. It can be used in both serverless mode or with a dedicated endpoint, supporting features like stop sequ...
class_definition
5,576
7,837
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/llm_engine.py
null
373
class TransformersEngine(HfEngine): """This engine uses a pre-initialized local text-generation pipeline.""" def __init__(self, pipeline: Pipeline, model_id: Optional[str] = None): super().__init__(model_id) self.pipeline = pipeline def generate( self, messages: List[Dict[s...
class_definition
7,840
8,887
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/llm_engine.py
null
374
class SpeechToTextTool(PipelineTool): default_checkpoint = "distil-whisper/distil-large-v3" description = "This is a tool that transcribes an audio into text. It returns the transcribed text." name = "transcriber" pre_processor_class = WhisperProcessor model_class = WhisperForConditionalGeneration ...
class_definition
763
1,495
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/speech_to_text.py
null
375
class CustomFormatter(logging.Formatter): grey = "\x1b[38;20m" bold_yellow = "\x1b[33;1m" red = "\x1b[31;20m" green = "\x1b[32;20m" bold_green = "\x1b[32;20;1m" bold_red = "\x1b[31;1m" bold_white = "\x1b[37;1m" orange = "\x1b[38;5;214m" bold_orange = "\x1b[38;5;214;1m" reset = "\...
class_definition
1,827
2,835
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
376
class Toolbox: """ The toolbox contains all tools that the agent can perform operations with, as well as a few methods to manage them. Args: tools (`List[Tool]`): The list of tools to instantiate the toolbox with add_base_tools (`bool`, defaults to `False`, *optional*, defau...
class_definition
6,369
10,031
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
377
class AgentError(Exception): """Base class for other agent-related exceptions""" def __init__(self, message): super().__init__(message) self.message = message
class_definition
10,034
10,217
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
378
class AgentParsingError(AgentError): """Exception raised for errors in parsing in the agent""" pass
class_definition
10,220
10,328
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
379
class AgentExecutionError(AgentError): """Exception raised for errors in execution in the agent""" pass
class_definition
10,331
10,443
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
380
class AgentMaxIterationsError(AgentError): """Exception raised for errors in execution in the agent""" pass
class_definition
10,446
10,562
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
381
class AgentGenerationError(AgentError): """Exception raised for errors in generation in the agent""" pass
class_definition
10,565
10,679
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
382
class Agent: def __init__( self, tools: Union[List[Tool], Toolbox], llm_engine: Callable = None, system_prompt: Optional[str] = None, tool_description_template: Optional[str] = None, additional_args: Dict = {}, max_iterations: int = 6, tool_parser: Opt...
class_definition
12,433
23,079
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
383
class CodeAgent(Agent): """ A class for an agent that solves the given task using a single block of code. It plans all its actions, then executes all in one shot. """ def __init__( self, tools: List[Tool], llm_engine: Optional[Callable] = None, system_prompt: Optional[st...
class_definition
23,082
27,909
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
384
class ReactAgent(Agent): """ This agent that solves the given task step by step, using the ReAct framework: While the objective is not reached, the agent will perform a cycle of thinking and acting. The action will be parsed from the LLM output: it consists in calls to tools from the toolbox, with argum...
class_definition
27,912
39,268
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
385
class ReactJsonAgent(ReactAgent): """ This agent that solves the given task step by step, using the ReAct framework: While the objective is not reached, the agent will perform a cycle of thinking and acting. The tool calls will be formulated by the LLM in JSON format, then parsed and executed. """ ...
class_definition
39,271
43,831
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
386
class ReactCodeAgent(ReactAgent): """ This agent that solves the given task step by step, using the ReAct framework: While the objective is not reached, the agent will perform a cycle of thinking and acting. The tool calls will be formulated by the LLM in code format, then parsed and executed. """ ...
class_definition
43,834
49,471
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
387
class ManagedAgent: def __init__(self, agent, name, description, additional_prompting=None, provide_run_summary=False): self.agent = agent self.name = name self.description = description self.additional_prompting = additional_prompting self.provide_run_summary = provide_run_s...
class_definition
49,507
52,065
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/agents.py
null
388
class TextToSpeechTool(PipelineTool): default_checkpoint = "microsoft/speecht5_tts" description = ( "This is a tool that reads an English text out loud. It returns a waveform object containing the sound." ) name = "text_to_speech" pre_processor_class = SpeechT5Processor model_class = Spe...
class_definition
898
2,467
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/text_to_speech.py
null
389
class DocumentQuestionAnsweringTool(PipelineTool): default_checkpoint = "naver-clova-ix/donut-base-finetuned-docvqa" description = "This is a tool that answers a question about an document (pdf). It returns a string that contains the answer to the question." name = "document_qa" pre_processor_class = Au...
class_definition
931
3,633
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/document_question_answering.py
null
390
class TranslationTool(PipelineTool): """ Example: ```py from transformers.agents import TranslationTool translator = TranslationTool() translator("This is a super nice API!", src_lang="English", tgt_lang="French") ``` """ lang_to_code = LANGUAGE_CODES default_checkpoint = "fac...
class_definition
6,764
8,670
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/translation.py
null
391
class PreTool: name: str inputs: Dict[str, str] output_type: type task: str description: str repo_id: str
class_definition
2,141
2,270
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/default_tools.py
null
392
class PythonInterpreterTool(Tool): name = "python_interpreter" description = "This is a tool that evaluates python code. It can be used to perform calculations." output_type = "string" def __init__(self, *args, authorized_imports=None, **kwargs): if authorized_imports is None: self...
class_definition
3,828
4,959
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/default_tools.py
null
393
class FinalAnswerTool(Tool): name = "final_answer" description = "Provides a final answer to the given problem." inputs = {"answer": {"type": "any", "description": "The final answer to the problem"}} output_type = "any" def forward(self, answer): return answer
class_definition
4,962
5,251
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/default_tools.py
null
394
class DuckDuckGoSearchTool(Tool): name = "web_search" description = """Perform a web search based on your query (think a Google search) then returns the top search results as a list of dict elements. Each result has keys 'title', 'href' and 'body'.""" inputs = {"query": {"type": "string", "description":...
class_definition
752
1,511
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/search.py
null
395
class VisitWebpageTool(Tool): name = "visit_webpage" description = "Visits a webpage at the given url and returns its content as a markdown string." inputs = { "url": { "type": "string", "description": "The url of the webpage to visit.", } } output_type = "str...
class_definition
1,514
2,776
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/search.py
null
396
class InterpreterError(ValueError): """ An error raised when the interpretor cannot evaluate a Python expression, due to syntax error or unsupported operations. """ pass
class_definition
933
1,123
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/python_interpreter.py
null
397
class BreakException(Exception): pass
class_definition
1,571
1,612
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/python_interpreter.py
null
398
class ContinueException(Exception): pass
class_definition
1,615
1,659
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/agents/python_interpreter.py
null
399