o GqBg~ã@shddlZddlmZddlmZddlmZddlmZm Z ddl m Z m Z dd„Z dd „Zd d „ZdS) éN)Ú AutoConfig)ÚPretrainedConfig)Úsnapshot_downloadÚ repo_exists)Úvalidate_repo_idÚHFValidationErrorc Cs2gd¢}t|dƒrt|jƒdkr|j}n|j}|durAt |¡sAzt|ƒ}Wnty:}zd}WYd}~nd}~ww|rAt|ƒ}g}|D]Q}t ||dƒ}t |t ƒrnz|  t j ||dd…¡¡WqEtd|›dƒ‚t |tƒr‚|  t j ||dd…¡¡qEt |tƒr|  |¡qE|dur–|  |¡qE|S)N)Úllm_cfgÚvision_tower_cfgÚmm_projector_cfgÚmask_encoder_cfgÚcontext_provider_cfgÚ _name_or_pathéFéüÿÿÿz&Cannot find resume path in config for ú!)ÚhasattrÚlenr Z resume_pathÚospÚexistsrrrÚgetattrÚ isinstanceÚdictÚappendÚosÚpathÚjoinÚ ValueErrorrÚstr)ÚconfigZ default_keysÚ root_pathZ valid_hf_repoÚeZ return_listÚkeyÚcfg©r#ú4/home/l/lo/longlian/describe-anything/model/utils.pyÚget_model_configs: €ÿ       €r%cCs0t |¡}|j}|D] }d| ¡vrdSq dS)zÕ Check if the model at the given path is a visual language model. Args: model_path (str): The path to the model. Returns: bool: True if the model is an MM model, False otherwise. ÚllavaTF)rÚfrom_pretrainedÚ architecturesÚlower)Ú model_pathrr(Ú architecturer#r#r$Ú is_mm_model<s  ÿr,cCs²t |¡}d|vrUd|jvrW|jdksJ‚tdƒtdƒtdƒ}| ¡dvrKtdƒt|jƒdks4J‚t|j d dƒd |jd <|  |¡td ƒdStd ƒt dƒdSdSdS)Nr&ÚllamazXYou are using newer LLaVA code base, while the checkpoint of v0 is from older code base.zVYou must upgrade the checkpoint to the new code base (this can be done automatically).z=Please confirm that you want to upgrade the checkpoint. [Y/N])ÚyÚyeszUpgrading checkpoint...éÚ model_typeZLlavaLlamaForCausalLMrzCheckpoint upgraded.zCheckpoint upgrade aborted.) rr'r1ÚprintÚinputr)rr(ÚsetattrÚ __class__Úsave_pretrainedÚexit)rr"Úconfirmr#r#r$Ú auto_upgradeNs( ÿÿ     îr9)rÚos.pathrrÚ transformersrrÚhuggingface_hubrrÚhuggingface_hub.utilsrrr%r,r9r#r#r#r$Ús  %