Stopping criteria not working with \n
Author: mostafamdy
Pull request: no

### System Info

transformers==4.41.2

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

StoppingCriteria code 
```
from transformers import StoppingCriteriaList,StoppingCriteria

class StoppingCriteriaSub(StoppingCriteria):
    def __init__(self, stops = [], encounters=1):
        super().__init__()
        self.stops = [stop.to("cuda") for stop in stops]

    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):
        for stop in self.stops:
            last_token = input_ids[0][-len(stop):]
            if torch.all(torch.eq(stop,last_token)):
                return True
        return False


stop_words = ["\n"] #,  
stop_words_ids = [tokenizer(stop_word, return_tensors='pt', add_special_tokens=False)['input_ids'].squeeze() for stop_word in stop_words]
stopping_criteria = StoppingCriteriaList([StoppingCriteriaSub(stops=stop_words_ids)])
```
model generate 
  ```
  outputs=model.generate(
                        **inputs.to(model.device),
                        max_length=MAX_LENGTH,
                        pad_token_id=tokenizer.eos_token_id,
                        do_sample = True,
                        temperature = 0.9,
                        top_p = 1,
                        num_return_sequences=3, 
                        stopping_criteria = stopping_criteria,
    )
```
error
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[105], line 15
     12     prompt=prompt.replace("\n"," ")
     13     inputs=tokenizer([prompt],return_tensors="pt")
---> 15     outputs=model.generate(
     16                         **inputs.to(model.device),
     17                         max_length=MAX_LENGTH,
     18                         pad_token_id=tokenizer.eos_token_id,
     19                         do_sample = True,
     20                         temperature = 0.9,
     21                         top_p = 1,
     22                         num_return_sequences=3, 
     23                         stopping_criteria = stopping_criteria,
     24     )
     25 #     print(outputs)
     26     text_ls=tokenizer.batch_decode(outputs,skip_special_tokens=True)

File /opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/transformers/generation/utils.py:1758, in GenerationMixin.generate(self, inputs, generation_config, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, assistant_model, streamer, negative_prompt_ids, negative_prompt_attention_mask, **kwargs)
   1750     input_ids, model_kwargs = self._expand_inputs_for_generation(
   1751         input_ids=input_ids,
   1752         expand_size=generation_config.num_return_sequences,
   1753         is_encoder_decoder=self.config.is_encoder_decoder,
   1754         **model_kwargs,
   1755     )
   1757     # 13. run sample (it degenerates to greedy search when `generation_config.do_sample=False`)
-> 1758     result = self._sample(
   1759         input_ids,
   1760         logits_processor=prepared_logits_processor,
   1761         logits_warper=prepared_logits_warper,
   1762         stopping_criteria=prepared_stopping_criteria,
   1763         generation_config=generation_config,
   1764         synced_gpus=synced_gpus,
   1765         streamer=streamer,
   1766         **model_kwargs,
   1767     )
   1769 elif generation_mode in (GenerationMode.BEAM_SAMPLE, GenerationMode.BEAM_SEARCH):
   1770     # 11. prepare logits warper
   1771     prepared_logits_warper = (
   1772         self._get_logits_warper(generation_config) if generation_config.do_sample else None
   1773     )

File /opt/conda/lib/python3.10/site-packages/transformers/generation/utils.py:2455, in GenerationMixin._sample(self, input_ids, logits_processor, stopping_criteria, generation_config, synced_gpus, streamer, logits_warper, **model_kwargs)
   2448         streamer.put(next_tokens.cpu())
   2449     model_kwargs = self._update_model_kwargs_for_generation(
   2450         outputs,
   2451         model_kwargs,
   2452         is_encoder_decoder=self.config.is_encoder_decoder,
   2453     )
-> 2455     unfinished_sequences = unfinished_sequences & ~stopping_criteria(input_ids, scores)
   2456     this_peer_finished = unfinished_sequences.max() == 0
   2458 if streamer is not None:

File /opt/conda/lib/python3.10/site-packages/transformers/generation/stopping_criteria.py:507, in StoppingCriteriaList.__call__(self, input_ids, scores, **kwargs)
    505 is_done = torch.full((input_ids.shape[0],), False, device=input_ids.device)
    506 for criteria in self:
--> 507     is_done = is_done | criteria(input_ids, scores, **kwargs)
    508 return is_done

Cell In[102], line 10, in StoppingCriteriaSub.__call__(self, input_ids, scores)
      8 def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):
      9     for stop in self.stops:
---> 10         last_token = input_ids[0][-len(stop):]
     11         if torch.all(torch.eq(stop,last_token)):
     12             return True

File /opt/conda/lib/python3.10/site-packages/torch/_tensor.py:968, in Tensor.__len__(self)
    966     return handle_torch_function(Tensor.__len__, (self,), self)
    967 if self.dim() == 0:
--> 968     raise TypeError("len() of a 0-d tensor")
    969 if torch._C._get_tracing_state():
    970     warnings.warn(
    971         "Using len to get tensor shape might cause the trace to be incorrect. "
    972         "Recommended usage would be tensor.shape[0]. "
   (...)
    976         stacklevel=2,
    977     )

TypeError: len() of a 0-d tensor
```

### Expected behavior

stop when see \n 

Comments: