Upload folder using huggingface_hub
Browse files
custom_generate/generate.py
CHANGED
|
@@ -7,9 +7,13 @@ from transformers.generation.utils import (
|
|
| 7 |
)
|
| 8 |
import torch.nn as nn
|
| 9 |
import logging
|
|
|
|
| 10 |
|
| 11 |
from .beam_search import BeamSearchScorer
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
class HammingDiversityLogitsProcessor(LogitsProcessor):
|
|
@@ -155,6 +159,7 @@ def _group_beam_search(
|
|
| 155 |
stopping_criteria: StoppingCriteriaList,
|
| 156 |
generation_config: GenerationConfig,
|
| 157 |
synced_gpus: bool,
|
|
|
|
| 158 |
**model_kwargs,
|
| 159 |
):
|
| 160 |
r"""
|
|
@@ -197,6 +202,9 @@ def _group_beam_search(
|
|
| 197 |
if generation_config.diversity_penalty == 0.0:
|
| 198 |
raise ValueError("Group beam search requires `diversity_penalty` to be greater than `0.0`, otherwise your groups will be identical.")
|
| 199 |
|
|
|
|
|
|
|
|
|
|
| 200 |
if generation_config.diversity_penalty is not None and generation_config.diversity_penalty > 0.0:
|
| 201 |
logits_processor.append(
|
| 202 |
HammingDiversityLogitsProcessor(
|
|
|
|
| 7 |
)
|
| 8 |
import torch.nn as nn
|
| 9 |
import logging
|
| 10 |
+
from typing import Optional, Union, TYPE_CHECKING
|
| 11 |
|
| 12 |
from .beam_search import BeamSearchScorer
|
| 13 |
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from transformers.generation.streamers import BaseStreamer
|
| 16 |
+
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
| 19 |
class HammingDiversityLogitsProcessor(LogitsProcessor):
|
|
|
|
| 159 |
stopping_criteria: StoppingCriteriaList,
|
| 160 |
generation_config: GenerationConfig,
|
| 161 |
synced_gpus: bool,
|
| 162 |
+
streamer: Optional["BaseStreamer"] = None,
|
| 163 |
**model_kwargs,
|
| 164 |
):
|
| 165 |
r"""
|
|
|
|
| 202 |
if generation_config.diversity_penalty == 0.0:
|
| 203 |
raise ValueError("Group beam search requires `diversity_penalty` to be greater than `0.0`, otherwise your groups will be identical.")
|
| 204 |
|
| 205 |
+
if streamer is not None:
|
| 206 |
+
raise ValueError("Group beam search does not support streaming")
|
| 207 |
+
|
| 208 |
if generation_config.diversity_penalty is not None and generation_config.diversity_penalty > 0.0:
|
| 209 |
logits_processor.append(
|
| 210 |
HammingDiversityLogitsProcessor(
|