class_docstr: Generator based on a Hugging Face model.
  This component provides an interface to generate text using a Hugging Face model that runs locally.
  
  Usage example:
  ```python
  from haystack.components.generators import HuggingFaceLocalGenerator
  
  generator = HuggingFaceLocalGenerator(model="google/flan-t5-large",
                                        task="text2text-generation",
                                        generation_kwargs={
                                          "max_new_tokens": 100,
                                          "temperature": 0.9,
                                          })
  
  print(generator.run("Who is the best American actor?"))
  # {'replies': ['John Cusack']}
  ```
docstr: Deserialize this component from a dictionary.
code: def from_dict(
      cls, data: Dict[str, Any]
  ) -> "HuggingFaceLocalGenerator":
      """
      Deserialize this component from a dictionary.
      """
      torch_and_transformers_import.check()
      init_params = data.get("init_parameters", {})
      huggingface_pipeline_kwargs = init_params.get(
          "huggingface_pipeline_kwargs", {}
      )
      model_kwargs = huggingface_pipeline_kwargs.get("model_kwargs", {})
  
      # convert string to torch.dtype
      # 1. torch_dtype can be specified in huggingface_pipeline_kwargs
      torch_dtype = huggingface_pipeline_kwargs.get("torch_dtype", None)
      if torch_dtype and torch_dtype.startswith("torch."):
          data["init_parameters"]["huggingface_pipeline_kwargs"][
              "torch_dtype"
          ] = getattr(torch, torch_dtype.strip("torch."))
      # 2. torch_dtype and bnb_4bit_compute_dtype can be specified in model_kwargs
      for key, value in model_kwargs.items():
          if key in [
              "torch_dtype",
              "bnb_4bit_compute_dtype",
          ] and value.startswith("torch."):
              data["init_parameters"]["huggingface_pipeline_kwargs"][
                  "model_kwargs"
              ][key] = getattr(torch, value.strip("torch."))
      # 3. bnb_4bit_compute_dtype can be specified in model_kwargs["quantization_config"]
      quantization_config = model_kwargs.get("quantization_config", {})
      bnb_4bit_compute_dtype = quantization_config.get(
          "bnb_4bit_compute_dtype", None
      )
      if bnb_4bit_compute_dtype and bnb_4bit_compute_dtype.startswith(
          "torch."
      ):
          data["init_parameters"]["huggingface_pipeline_kwargs"][
              "model_kwargs"
          ]["quantization_config"]["bnb_4bit_compute_dtype"] = getattr(
              torch, bnb_4bit_compute_dtype.strip("torch.")
          )
  
      return default_from_dict(cls, data)
  
file_path: haystack/haystack/components/generators/hugging_face_local.py
imports: import logging
  from typing import Any, Dict, List, Literal, Optional, Union
  from haystack import component, default_to_dict, default_from_dict
  from haystack.components.generators.hf_utils import StopWordsCriteria
  from haystack.lazy_imports import LazyImport
label_desc: Use image node_id 5 for calling the HuggingFaceLocalGenerator obj's underlying member method code with example usage: obj.from_dict(cls, data) and returns: default_from_dict