Aluode/PerceptionLabPortable
0
1# Copyright 2022 The HuggingFace Team. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15from typing import TYPE_CHECKING16 17from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available18 19 20_import_structure = {21 "configuration_utils": [22 "BaseWatermarkingConfig",23 "CompileConfig",24 "GenerationConfig",25 "GenerationMode",26 "SynthIDTextWatermarkingConfig",27 "WatermarkingConfig",28 ],29 "streamers": ["AsyncTextIteratorStreamer", "BaseStreamer", "TextIteratorStreamer", "TextStreamer"],30}31 32try:33 if not is_torch_available():34 raise OptionalDependencyNotAvailable()35except OptionalDependencyNotAvailable:36 pass37else:38 _import_structure["beam_constraints"] = [39 "Constraint",40 "ConstraintListState",41 "DisjunctiveConstraint",42 "PhrasalConstraint",43 ]44 _import_structure["beam_search"] = [45 "BeamHypotheses",46 "BeamScorer",47 "ConstrainedBeamSearchScorer",48 ]49 _import_structure["candidate_generator"] = [50 "AssistedCandidateGenerator",51 "CandidateGenerator",52 "EarlyExitCandidateGenerator",53 "PromptLookupCandidateGenerator",54 ]55 _import_structure["logits_process"] = [56 "AlternatingCodebooksLogitsProcessor",57 "ClassifierFreeGuidanceLogitsProcessor",58 "EncoderNoRepeatNGramLogitsProcessor",59 "EncoderRepetitionPenaltyLogitsProcessor",60 "EpsilonLogitsWarper",61 "EtaLogitsWarper",62 "ExponentialDecayLengthPenalty",63 "ForcedBOSTokenLogitsProcessor",64 "ForcedEOSTokenLogitsProcessor",65 "InfNanRemoveLogitsProcessor",66 "LogitNormalization",67 "LogitsProcessor",68 "LogitsProcessorList",69 "MinLengthLogitsProcessor",70 "MinNewTokensLengthLogitsProcessor",71 "MinPLogitsWarper",72 "NoBadWordsLogitsProcessor",73 "NoRepeatNGramLogitsProcessor",74 "PrefixConstrainedLogitsProcessor",75 "RepetitionPenaltyLogitsProcessor",76 "SequenceBiasLogitsProcessor",77 "SuppressTokensLogitsProcessor",78 "SuppressTokensAtBeginLogitsProcessor",79 "SynthIDTextWatermarkLogitsProcessor",80 "TemperatureLogitsWarper",81 "TopKLogitsWarper",82 "TopPLogitsWarper",83 "TypicalLogitsWarper",84 "UnbatchedClassifierFreeGuidanceLogitsProcessor",85 "WhisperTimeStampLogitsProcessor",86 "WatermarkLogitsProcessor",87 ]88 _import_structure["stopping_criteria"] = [89 "MaxLengthCriteria",90 "MaxTimeCriteria",91 "ConfidenceCriteria",92 "EosTokenCriteria",93 "StoppingCriteria",94 "StoppingCriteriaList",95 "validate_stopping_criteria",96 "StopStringCriteria",97 ]98 _import_structure["continuous_batching"] = [99 "ContinuousMixin",100 ]101 _import_structure["utils"] = [102 "GenerationMixin",103 "GreedySearchEncoderDecoderOutput",104 "GreedySearchDecoderOnlyOutput",105 "SampleEncoderDecoderOutput",106 "SampleDecoderOnlyOutput",107 "BeamSearchEncoderDecoderOutput",108 "BeamSearchDecoderOnlyOutput",109 "BeamSampleEncoderDecoderOutput",110 "BeamSampleDecoderOnlyOutput",111 "ContrastiveSearchEncoderDecoderOutput",112 "ContrastiveSearchDecoderOnlyOutput",113 "GenerateBeamDecoderOnlyOutput",114 "GenerateBeamEncoderDecoderOutput",115 "GenerateDecoderOnlyOutput",116 "GenerateEncoderDecoderOutput",117 ]118 _import_structure["watermarking"] = [119 "WatermarkDetector",120 "WatermarkDetectorOutput",121 "BayesianDetectorModel",122 "BayesianDetectorConfig",123 "SynthIDTextWatermarkDetector",124 ]125 126try:127 if not is_tf_available():128 raise OptionalDependencyNotAvailable()129except OptionalDependencyNotAvailable:130 pass131else:132 _import_structure["tf_logits_process"] = [133 "TFForcedBOSTokenLogitsProcessor",134 "TFForcedEOSTokenLogitsProcessor",135 "TFForceTokensLogitsProcessor",136 "TFLogitsProcessor",137 "TFLogitsProcessorList",138 "TFLogitsWarper",139 "TFMinLengthLogitsProcessor",140 "TFNoBadWordsLogitsProcessor",141 "TFNoRepeatNGramLogitsProcessor",142 "TFRepetitionPenaltyLogitsProcessor",143 "TFSuppressTokensAtBeginLogitsProcessor",144 "TFSuppressTokensLogitsProcessor",145 "TFTemperatureLogitsWarper",146 "TFTopKLogitsWarper",147 "TFTopPLogitsWarper",148 ]149 _import_structure["tf_utils"] = [150 "TFGenerationMixin",151 "TFGreedySearchDecoderOnlyOutput",152 "TFGreedySearchEncoderDecoderOutput",153 "TFSampleEncoderDecoderOutput",154 "TFSampleDecoderOnlyOutput",155 "TFBeamSearchEncoderDecoderOutput",156 "TFBeamSearchDecoderOnlyOutput",157 "TFBeamSampleEncoderDecoderOutput",158 "TFBeamSampleDecoderOnlyOutput",159 "TFContrastiveSearchEncoderDecoderOutput",160 "TFContrastiveSearchDecoderOnlyOutput",161 ]162 163try:164 if not is_flax_available():165 raise OptionalDependencyNotAvailable()166except OptionalDependencyNotAvailable:167 pass168else:169 _import_structure["flax_logits_process"] = [170 "FlaxForcedBOSTokenLogitsProcessor",171 "FlaxForcedEOSTokenLogitsProcessor",172 "FlaxForceTokensLogitsProcessor",173 "FlaxLogitsProcessor",174 "FlaxLogitsProcessorList",175 "FlaxLogitsWarper",176 "FlaxMinLengthLogitsProcessor",177 "FlaxSuppressTokensAtBeginLogitsProcessor",178 "FlaxSuppressTokensLogitsProcessor",179 "FlaxTemperatureLogitsWarper",180 "FlaxTopKLogitsWarper",181 "FlaxTopPLogitsWarper",182 "FlaxWhisperTimeStampLogitsProcessor",183 "FlaxNoRepeatNGramLogitsProcessor",184 ]185 _import_structure["flax_utils"] = [186 "FlaxGenerationMixin",187 "FlaxGreedySearchOutput",188 "FlaxSampleOutput",189 "FlaxBeamSearchOutput",190 ]191 192if TYPE_CHECKING:193 from .configuration_utils import (194 BaseWatermarkingConfig,195 CompileConfig,196 GenerationConfig,197 GenerationMode,198 SynthIDTextWatermarkingConfig,199 WatermarkingConfig,200 )201 from .streamers import AsyncTextIteratorStreamer, BaseStreamer, TextIteratorStreamer, TextStreamer202 203 try:204 if not is_torch_available():205 raise OptionalDependencyNotAvailable()206 except OptionalDependencyNotAvailable:207 pass208 else:209 from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint210 from .beam_search import BeamHypotheses, BeamScorer, ConstrainedBeamSearchScorer211 from .candidate_generator import (212 AssistedCandidateGenerator,213 CandidateGenerator,214 EarlyExitCandidateGenerator,215 PromptLookupCandidateGenerator,216 )217 from .continuous_batching import ContinuousMixin218 from .logits_process import (219 AlternatingCodebooksLogitsProcessor,220 ClassifierFreeGuidanceLogitsProcessor,221 EncoderNoRepeatNGramLogitsProcessor,222 EncoderRepetitionPenaltyLogitsProcessor,223 EpsilonLogitsWarper,224 EtaLogitsWarper,225 ExponentialDecayLengthPenalty,226 ForcedBOSTokenLogitsProcessor,227 ForcedEOSTokenLogitsProcessor,228 InfNanRemoveLogitsProcessor,229 LogitNormalization,230 LogitsProcessor,231 LogitsProcessorList,232 MinLengthLogitsProcessor,233 MinNewTokensLengthLogitsProcessor,234 MinPLogitsWarper,235 NoBadWordsLogitsProcessor,236 NoRepeatNGramLogitsProcessor,237 PrefixConstrainedLogitsProcessor,238 RepetitionPenaltyLogitsProcessor,239 SequenceBiasLogitsProcessor,240 SuppressTokensAtBeginLogitsProcessor,241 SuppressTokensLogitsProcessor,242 SynthIDTextWatermarkLogitsProcessor,243 TemperatureLogitsWarper,244 TopKLogitsWarper,245 TopPLogitsWarper,246 TypicalLogitsWarper,247 UnbatchedClassifierFreeGuidanceLogitsProcessor,248 WatermarkLogitsProcessor,249 WhisperTimeStampLogitsProcessor,250 )251 from .stopping_criteria import (252 ConfidenceCriteria,253 EosTokenCriteria,254 MaxLengthCriteria,255 MaxTimeCriteria,256 StoppingCriteria,257 StoppingCriteriaList,258 StopStringCriteria,259 validate_stopping_criteria,260 )261 from .utils import (262 BeamSampleDecoderOnlyOutput,263 BeamSampleEncoderDecoderOutput,264 BeamSearchDecoderOnlyOutput,265 BeamSearchEncoderDecoderOutput,266 ContrastiveSearchDecoderOnlyOutput,267 ContrastiveSearchEncoderDecoderOutput,268 GenerateBeamDecoderOnlyOutput,269 GenerateBeamEncoderDecoderOutput,270 GenerateDecoderOnlyOutput,271 GenerateEncoderDecoderOutput,272 GenerationMixin,273 GreedySearchDecoderOnlyOutput,274 GreedySearchEncoderDecoderOutput,275 SampleDecoderOnlyOutput,276 SampleEncoderDecoderOutput,277 )278 from .watermarking import (279 BayesianDetectorConfig,280 BayesianDetectorModel,281 SynthIDTextWatermarkDetector,282 WatermarkDetector,283 WatermarkDetectorOutput,284 )285 286 try:287 if not is_tf_available():288 raise OptionalDependencyNotAvailable()289 except OptionalDependencyNotAvailable:290 pass291 else:292 from .tf_logits_process import (293 TFForcedBOSTokenLogitsProcessor,294 TFForcedEOSTokenLogitsProcessor,295 TFForceTokensLogitsProcessor,296 TFLogitsProcessor,297 TFLogitsProcessorList,298 TFLogitsWarper,299 TFMinLengthLogitsProcessor,300 TFNoBadWordsLogitsProcessor,301 TFNoRepeatNGramLogitsProcessor,302 TFRepetitionPenaltyLogitsProcessor,303 TFSuppressTokensAtBeginLogitsProcessor,304 TFSuppressTokensLogitsProcessor,305 TFTemperatureLogitsWarper,306 TFTopKLogitsWarper,307 TFTopPLogitsWarper,308 )309 from .tf_utils import (310 TFBeamSampleDecoderOnlyOutput,311 TFBeamSampleEncoderDecoderOutput,312 TFBeamSearchDecoderOnlyOutput,313 TFBeamSearchEncoderDecoderOutput,314 TFContrastiveSearchDecoderOnlyOutput,315 TFContrastiveSearchEncoderDecoderOutput,316 TFGenerationMixin,317 TFGreedySearchDecoderOnlyOutput,318 TFGreedySearchEncoderDecoderOutput,319 TFSampleDecoderOnlyOutput,320 TFSampleEncoderDecoderOutput,321 )322 323 try:324 if not is_flax_available():325 raise OptionalDependencyNotAvailable()326 except OptionalDependencyNotAvailable:327 pass328 else:329 from .flax_logits_process import (330 FlaxForcedBOSTokenLogitsProcessor,331 FlaxForcedEOSTokenLogitsProcessor,332 FlaxForceTokensLogitsProcessor,333 FlaxLogitsProcessor,334 FlaxLogitsProcessorList,335 FlaxLogitsWarper,336 FlaxMinLengthLogitsProcessor,337 FlaxNoRepeatNGramLogitsProcessor,338 FlaxSuppressTokensAtBeginLogitsProcessor,339 FlaxSuppressTokensLogitsProcessor,340 FlaxTemperatureLogitsWarper,341 FlaxTopKLogitsWarper,342 FlaxTopPLogitsWarper,343 FlaxWhisperTimeStampLogitsProcessor,344 )345 from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput346else:347 import sys348 349 sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)350 