File tree 3 files changed +13
-20
lines changed
3 files changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -136,9 +136,7 @@ def _template_substitution(
136
136
return TemplateWithArithmetic (template ).substitute (substitutions )
137
137
138
138
139
- def _load_architecture_json (name : str ) -> ModelArchitecture :
140
- with importlib .resources .open_text (mergekit ._data .architectures , name ) as f :
141
- text = f .read ()
139
+ def _load_architecture_json (text : str ) -> ModelArchitecture :
142
140
data = json .loads (text )
143
141
kind = data .get ("kind" , "module" )
144
142
if kind == "modular" :
@@ -174,9 +172,10 @@ def _load_all_architectures() -> (
174
172
Tuple [List [ModelArchitecture ], Dict [str , List [ModelArchitecture ]]]
175
173
):
176
174
architectures : List [ModelArchitecture ] = []
177
- for f in importlib .resources .contents (mergekit ._data .architectures ):
178
- if f .lower ().endswith (".json" ):
179
- architectures .append (_load_architecture_json (f ))
175
+ for f in importlib .resources .files (mergekit ._data .architectures ).iterdir ():
176
+ if f .is_file () and f .name .lower ().endswith (".json" ):
177
+ text = f .read_text ()
178
+ architectures .append (_load_architecture_json (text ))
180
179
181
180
name_to_arch : Dict [str , List [JsonModuleArchitecture ]] = {}
182
181
for arch_info in architectures :
Original file line number Diff line number Diff line change @@ -187,11 +187,12 @@ def _set_chat_template(
187
187
chat_template = Counter (model_templates ).most_common (1 )[0 ][0 ]
188
188
LOG .info (f"Auto-selected chat template: { chat_template } " )
189
189
190
- elif importlib .resources .is_resource (chat_templates , chat_template + ".jinja" ):
191
- with importlib .resources .open_text (
192
- chat_templates , chat_template + ".jinja"
193
- ) as fp :
194
- chat_template = fp .read ()
190
+ elif (
191
+ t := importlib .resources .files (chat_templates ).joinpath (
192
+ chat_template + ".jinja"
193
+ )
194
+ ).is_file ():
195
+ chat_template = t .read_text ()
195
196
196
197
elif len (chat_template ) < 20 or "{" not in chat_template :
197
198
raise RuntimeError (f"Invalid chat template: { chat_template } " )
Original file line number Diff line number Diff line change @@ -85,18 +85,11 @@ minversion = "6.0"
85
85
filterwarnings = [
86
86
" ignore::pydantic.PydanticDeprecatedSince20:huggingface_hub.*:" ,
87
87
" ignore::FutureWarning:huggingface_hub.*:" ,
88
- " ignore:(read_text|open_text|contents|is_resource) is deprecated:DeprecationWarning" , # yes i know, but files() doesn't exist in 3.8
89
88
" ignore:Attempting Automatic Merge:UserWarning" ,
90
89
" ignore:No architecture config available:UserWarning" ,
91
90
]
92
91
testpaths = [" tests" ]
93
92
94
93
[dependency-groups ]
95
- test = [
96
- " pytest~=8.3.5" ,
97
- ]
98
- dev = [
99
- " black~=24.10.0" ,
100
- " isort~=5.13.2" ,
101
- " pre-commit~=4.1.0" ,
102
- ]
94
+ test = [" pytest~=8.3.5" ]
95
+ dev = [" black~=24.10.0" , " isort~=5.13.2" , " pre-commit~=4.1.0" ]
You can’t perform that action at this time.
0 commit comments