chore(typing): Add type checking to `src/transformers/quantizers` (#44412)
* chore(typing): add `ty` type checking for src/transformers/generation
Add type declarations for mixin host-class attributes on GenerationMixin,
class-level annotations for dynamically-set attributes on GenerationConfig,
and fix minor typing issues in candidate_generator, watermarking, and
stopping_criteria. Create _typing.py Protocol for documentation/reuse.
* extend make file
* chore(typing): further reduce ty diagnostics (36→18), replace assert with if guards
- Replace assert narrowing with if guards (candidate_generator.py)
- Add if-guard for model_kwargs None in _prepare_model_inputs and
_maybe_initialize_input_ids_for_generation
- Add if-guard for encoder_input_ids None checks
- Fix save_directory.split() for PathLike by wrapping with str()
- Fix tuple[Tensor] reassignment in compute_transition_scores
- Add type annotation for self.model in WhisperTimeStampLogitsProcessor
- Add type annotation for self.sequence_bias in SequenceBiasLogitsProcessor
- Add no-assert rule to AGENTS.md typing strategy
* more tweaking
* fix get word size
* date
* cast value
* @zucchini-nlp reviews
* model_kwargs cannot be None, fix type annotations
* removed redundancy
* bypass type checking to reduce code complexity
* de-vectorize
* unified _typing
* explain why we pollute inheritance with a protocol
* do not import torch for type checking, it breaks on CI logging usage
* Add check_types.py to wrap ty type checking
* improved ty usage
* chore(typing): Add type checking to src/transformers/quantizers
* fix merge error
* reworked the typing using previous PR best practices
* format and torch.neuron fix
* revert bad upstream merge
* narrow isinstance
* cleaner const, also 1.23.99 vs 1.24.0
* clean up old cast
* removing leftover
* lets just use setattr
* tweaked one more optimum version
* setattr again
* more setattr/getattr patyterns
* more cleanups
* fmt
* cleanups from rebase abd ty 0.20.0
* fix ignores
* const for torchao version
* simplify call
Co-authored-by: vasqu
* use is_torch_greater_or_equal
* use type guard
* remove the getattr() pattenr
* reworked the approach
* Update src/transformers/quantizers/quantizer_sinq.py
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
* Update src/transformers/quantizers/quantizer_quanto.py
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
* class is there we can use it
---------
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>