src/transformers/generation_utils.py/GenerationMixin/_get_stopping_criteria
class GenerationMixin:    def _get_stopping_criteria(
        self, max_length: Optional[int], max_time: Optional[float], max_new_tokens: Optional[int], start_length: int
    ) -> StoppingCriteriaList:
        stopping_criteria = StoppingCriteriaList()
        if max_length is not None:
            stopping_criteria.append(MaxLengthCriteria(max_length=max_length))
        if max_time is not None:
            stopping_criteria.append(MaxTimeCriteria(max_time=max_time))
        if max_new_tokens is not None:
            stopping_criteria.append(MaxNewTokensCriteria(start_length=start_length, max_new_tokens=max_new_tokens))
        return stopping_criteria