code: def test_text_streamer_decode_kwargs(self):
      # Tests that we can pass `decode_kwargs` to the streamer to control how the tokens are decoded. Must be tested
      # with actual models -- the dummy models' tokenizers are not aligned with their models, and
      # `skip_special_tokens=True` has no effect on them
      tokenizer = AutoTokenizer.from_pretrained("distilgpt2")
      model = AutoModelForCausalLM.from_pretrained("distilgpt2").to(
          torch_device
      )
      model.config.eos_token_id = -1
  
      input_ids = (
          torch.ones((1, 5), device=torch_device).long()
          * model.config.bos_token_id
      )
      with CaptureStdout() as cs:
          streamer = TextStreamer(tokenizer, skip_special_tokens=True)
          model.generate(
              input_ids,
              max_new_tokens=1,
              do_sample=False,
              streamer=streamer,
          )
  
      # The prompt contains a special token, so the streamer should not print it. As such, the output text, when
      # re-tokenized, must only contain one token
      streamer_text = cs.out[:-1]  # Remove the final "\n"
      streamer_text_tokenized = tokenizer(
          streamer_text, return_tensors="pt"
      )
      self.assertEqual(streamer_text_tokenized.input_ids.shape, (1, 1))
  
file_path: transformers/tests/generation/test_streamers.py
imports: import unittest
  from queue import Empty
  from threading import Thread
  from transformers import AutoTokenizer, TextIteratorStreamer, TextStreamer, is_torch_available
  from transformers.testing_utils import CaptureStdout, require_torch, torch_device
  from ..test_modeling_common import ids_tensor
label_desc: Use image node_id 4 for calling the StreamerTester obj's underlying member method code with example usage: obj.test_text_streamer_decode_kwargs() without return types