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: Serialize this component to a dictionary.
code: def to_dict(self) -> Dict[str, Any]:
      """
      Serialize this component to a dictionary.
      """
      serialization_dict = default_to_dict(
          self,
          huggingface_pipeline_kwargs=self.huggingface_pipeline_kwargs,
          generation_kwargs=self.generation_kwargs,
          stop_words=self.stop_words,
      )
  
      huggingface_pipeline_kwargs = serialization_dict[
          "init_parameters"
      ]["huggingface_pipeline_kwargs"]
      # we don't want to serialize valid tokens
      if isinstance(huggingface_pipeline_kwargs["token"], str):
          serialization_dict["init_parameters"][
              "huggingface_pipeline_kwargs"
          ].pop("token")
      # convert torch.dtype to string for serialization
      # 1. torch_dtype can be specified in huggingface_pipeline_kwargs
      torch_dtype = huggingface_pipeline_kwargs.get("torch_dtype", None)
      if isinstance(torch_dtype, torch.dtype):
          serialization_dict["init_parameters"][
              "huggingface_pipeline_kwargs"
          ]["torch_dtype"] = str(torch_dtype)
      # 2. torch_dtype and bnb_4bit_compute_dtype can be specified in model_kwargs
      model_kwargs = huggingface_pipeline_kwargs.get("model_kwargs", {})
      for key, value in model_kwargs.items():
          if key in [
              "torch_dtype",
              "bnb_4bit_compute_dtype",
          ] and isinstance(value, torch.dtype):
              serialization_dict["init_parameters"][
                  "huggingface_pipeline_kwargs"
              ]["model_kwargs"][key] = str(value)
      # 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 isinstance(bnb_4bit_compute_dtype, torch.dtype):
          serialization_dict["init_parameters"][
              "huggingface_pipeline_kwargs"
          ]["model_kwargs"]["quantization_config"][
              "bnb_4bit_compute_dtype"
          ] = str(
              bnb_4bit_compute_dtype
          )
  
      return serialization_dict
  
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 4 for calling the HuggingFaceLocalGenerator obj's underlying member method code with example usage: obj.to_dict() and returns: serialization_dict