File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 6868)
6969from  .utils .chat_template_utils  import  _compile_jinja_template , _render_with_assistant_indices 
7070from  .utils .import_utils  import  PROTOBUF_IMPORT_ERROR 
71+ from  huggingface_hub  import  list_repo_tree 
7172
7273
7374if  TYPE_CHECKING :
@@ -1966,6 +1967,18 @@ def from_pretrained(
19661967                    "tokenizer_file" : FULL_TOKENIZER_FILE ,
19671968                    "chat_template_file" : CHAT_TEMPLATE_FILE ,
19681969                }
1970+                 if  is_local :
1971+                     template_dir  =  Path (pretrained_model_name_or_path , "templates" )
1972+                     if  template_dir .is_dir ():
1973+                         for  template_file  in  template_dir .glob ("*.jinja" ):
1974+                             template_name  =  template_file .name .removesuffix (".jinja" )
1975+                             additional_files_names [f"{ template_name }  ] =  f"templates/{ template_file .name }  
1976+                 else :
1977+                     for  template_file  in  list_repo_tree (pretrained_model_name_or_path , path_in_repo = "templates" , recursive = False ):
1978+                         if  not  template_file .endswith (".jinja" ):
1979+                             continue 
1980+                         template_name  =  template_file .split ('/' )[- 1 ].removesuffix (".jinja" )
1981+                         additional_files_names [f"{ template_name }  ] =  template_file   # This might be wrong! 
19691982                vocab_files  =  {** cls .vocab_files_names , ** additional_files_names }
19701983                if  "tokenizer_file"  in  vocab_files :
19711984                    # Try to get the tokenizer config to see if there are versioned tokenizer files. 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments