Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
e7231e84
"git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "7e2a550c9a569910fa0f99413087db9d22a9fed6"
Commit
e7231e84
authored
Jan 23, 2024
by
lintangsutawika
Browse files
moved import_function into the config loading file
parent
d352a549
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
lm_eval/utils.py
lm_eval/utils.py
+21
-21
No files found.
lm_eval/utils.py
View file @
e7231e84
...
@@ -472,28 +472,10 @@ def get_git_commit_hash():
...
@@ -472,28 +472,10 @@ def get_git_commit_hash():
return
git_hash
return
git_hash
def
import_function
(
loader
,
node
):
function_name
=
loader
.
construct_scalar
(
node
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
if
isinstance
(
module_name
,
list
):
module_name
=
"."
.
join
(
module_name
)
module_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
module_name
)))
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
spec
.
loader
.
exec_module
(
module
)
function
=
getattr
(
module
,
function_name
)
return
function
def
ignore_constructor
(
loader
,
node
):
return
node
def
simple_load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
simple_load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
ignore_constructor
(
loader
,
node
):
return
node
yaml
.
add_constructor
(
"!function"
,
ignore_constructor
)
yaml
.
add_constructor
(
"!function"
,
ignore_constructor
)
with
open
(
yaml_path
,
"rb"
)
as
file
:
with
open
(
yaml_path
,
"rb"
)
as
file
:
yaml_config
=
yaml
.
full_load
(
file
)
yaml_config
=
yaml
.
full_load
(
file
)
...
@@ -501,6 +483,24 @@ def simple_load_yaml_config(yaml_path=None, yaml_config=None, yaml_dir=None):
...
@@ -501,6 +483,24 @@ def simple_load_yaml_config(yaml_path=None, yaml_config=None, yaml_dir=None):
def
load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
import_function
(
loader
,
node
):
function_name
=
loader
.
construct_scalar
(
node
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
if
isinstance
(
module_name
,
list
):
module_name
=
"."
.
join
(
module_name
)
module_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
module_name
))
)
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
spec
.
loader
.
exec_module
(
module
)
function
=
getattr
(
module
,
function_name
)
return
function
# Add the import_function constructor to the YAML loader
# Add the import_function constructor to the YAML loader
yaml
.
add_constructor
(
"!function"
,
import_function
)
yaml
.
add_constructor
(
"!function"
,
import_function
)
if
yaml_config
is
None
:
if
yaml_config
is
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment