Fix decoder layer return handling + cache 5.x
Browse files100 unmodified lines101102103104105106107108109110111112102 unmodified lines215216217218219220221222223224225226227100 unmodified linesuse_cache = Falseuse_legacy_cache = Falseif use_cache and not isinstance(past_key_values, Cache):use_legacy_cache = True# pyre-fixme[6]: For 1st argument expected# `Optional[Tuple[Tuple[FloatTensor]]]` but got# `Optional[List[FloatTensor]]`.past_key_values = DynamicCache.from_legacy_cache(past_key_values)logger.warning_once("We detected that you are passing `past_key_values` as a tuple and this is deprecated and will be removed in v4.43. ""Please use an appropriate `Cache` class (https://huggingface.co/docs/transformers/v4.41.3/en/internal/generation_utils#transformers.Cache)"102 unmodified linescache_position=cache_position,)hidden_states = layer_outputs[0]if use_cache:next_decoder_cache = layer_outputs[2 if output_attentions else 1]if output_attentions:all_self_attns += (layer_outputs[1],)# pyre-fixme[16]: `CambrianQwenModel` has no attribute `norm`.hidden_states = self.norm(hidden_states)100 unmodified lines101102103104105106107108109110111112113114115116117118119120121122123124125126127102 unmodified lines230231232233234235236237238239240241242243244245246247248249250251252253254255256100 unmodified linesuse_cache = Falseuse_legacy_cache = False# 5.x: jika past_key_values None dan use_cache, buat DynamicCache baruif use_cache and past_key_values is None:try:from transformers.cache_utils import DynamicCache as _DCpast_key_values = _DC(config=self.config)except Exception:past_key_values = DynamicCache()use_legacy_cache = Falseelif use_cache and not isinstance(past_key_values, Cache):use_legacy_cache = True# pyre-fixme[6]: For 1st argument expected# `Optional[Tuple[Tuple[FloatTensor]]]` but got# `Optional[List[FloatTensor]]`.try:past_key_values = DynamicCache.from_legacy_cache(past_key_values)except Exception:from transformers.cache_utils import DynamicCache as _DC2past_key_values = _DC2(config=self.config)use_legacy_cache = Falselogger.warning_once("We detected that you are passing `past_key_values` as a tuple and this is deprecated and will be removed in v4.43. ""Please use an appropriate `Cache` class (https://huggingface.co/docs/transformers/v4.41.3/en/internal/generation_utils#transformers.Cache)"102 unmodified linescache_position=cache_position,)# 5.x: decoder_layer returns Tensor langsung, 4.x return tupleif isinstance(layer_outputs, tuple):hidden_states = layer_outputs[0]if use_cache:# 4.x: past_key_values di-return sebagai elemen tupletry:next_decoder_cache = layer_outputs[2 if output_attentions else 1]except Exception:next_decoder_cache = past_key_valuesif output_attentions:try:all_self_attns += (layer_outputs[1],)except Exception:passelse:hidden_states = layer_outputsif use_cache:next_decoder_cache = past_key_valuesif output_attentions and isinstance(layer_outputs, tuple):pass # sudah handle di atas# pyre-fixme[16]: `CambrianQwenModel` has no attribute `norm`.hidden_states = self.norm(hidden_states)
longvu/language_model/cambrian_qwen.py+37-8