@@ -16,14 +16,29 @@ class AttributeDict(dict):
1616 >>> 42
1717 """
1818
19+ def __init__ (self , * args , ** kwargs ):
20+ super ().__init__ (* args , ** kwargs )
21+ object .__setattr__ (self , "_used" , set ())
22+
1923 def __getattr__ (self , key : str ) -> any :
2024 try :
21- return self [key ]
25+ value = self [key ]
26+ self ._used .add (key )
27+ return value
2228 except KeyError :
2329 raise AttributeError (f'Missing attribute "{ key } "' )
2430
2531 def __setattr__ (self , key : str , value : any ) -> None :
2632 self [key ] = value
33+ self ._used .discard (key )
34+
35+ def used_items (self ) -> dict :
36+ """Returns the items that have been used at least once after being set.
37+
38+ Returns:
39+ dict: the used items.
40+ """
41+ return {k : self [k ] for k in self ._used }
2742
2843
2944class Timer (object ):
@@ -57,7 +72,7 @@ def time(self):
5772
5873
5974def dump_log (log_path , metrics = None , split = None , config = None ):
60- """Write log including config and the evaluation scores.
75+ """Write log including the used items of config and the evaluation scores.
6176
6277 Args:
6378 log_path(str): path to log path
@@ -73,7 +88,7 @@ def dump_log(log_path, metrics=None, split=None, config=None):
7388 result = dict ()
7489
7590 if config :
76- config_to_save = copy .deepcopy (dict ( config ))
91+ config_to_save = copy .deepcopy (config . used_items ( ))
7792 config_to_save .pop ("device" , None ) # delete if device exists
7893 result ["config" ] = config_to_save
7994 if split and metrics :
0 commit comments