halib 0.2.29__tar.gz → 0.2.31__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {halib-0.2.29 → halib-0.2.31}/PKG-INFO +3 -3
- {halib-0.2.29 → halib-0.2.31}/README.md +2 -2
- {halib-0.2.29 → halib-0.2.31}/halib/common/common.py +24 -13
- {halib-0.2.29 → halib-0.2.31}/halib/utils/dict.py +93 -5
- {halib-0.2.29 → halib-0.2.31}/halib.egg-info/PKG-INFO +3 -3
- {halib-0.2.29 → halib-0.2.31}/setup.py +1 -1
- {halib-0.2.29 → halib-0.2.31}/.gitignore +0 -0
- {halib-0.2.29 → halib-0.2.31}/GDriveFolder.txt +0 -0
- {halib-0.2.29 → halib-0.2.31}/LICENSE.txt +0 -0
- {halib-0.2.29 → halib-0.2.31}/MANIFEST.in +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/common/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/common/rich_color.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/core/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/core/base_config.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/core/base_exp.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/core/param_gen.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/core/wandb_op.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/data/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/data/dataclass_util.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/data/dataset.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/data/torchloader.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/flop_calc.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/gpu_mon.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/perfcalc.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/perfmetrics.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/perftb.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/perf/profiler.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/viz/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/exp/viz/plot.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/csvfile.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/ipynb.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/jsonfile.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/textfile.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/videofile.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/filetype/yamlfile.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/online/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/online/gdrive.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/online/gdrive_mkdir.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/online/projectmake.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/online/tele_noti.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/system/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/system/_list_pc.csv +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/system/cmd.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/system/filesys.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/system/path.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/utils/__init__.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/utils/list.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib/utils/slack.py +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib.egg-info/SOURCES.txt +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib.egg-info/dependency_links.txt +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib.egg-info/requires.txt +0 -0
- {halib-0.2.29 → halib-0.2.31}/halib.egg-info/top_level.txt +0 -0
- {halib-0.2.29 → halib-0.2.31}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.31
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -57,11 +57,11 @@ Dynamic: summary
|
|
|
57
57
|
|
|
58
58
|
## v0.2.x (Experiment & Core Updates)
|
|
59
59
|
|
|
60
|
-
### **v0.2.
|
|
60
|
+
### **v0.2.31**
|
|
61
61
|
|
|
62
62
|
- ✨ **New Feature:**: add `common.common.log_func` as decorator to log function entry, exit, with execution time and arguments.
|
|
63
63
|
|
|
64
|
-
- 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `
|
|
64
|
+
- 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_exclude/include` and `prune` function
|
|
65
65
|
|
|
66
66
|
### **v0.2.28**
|
|
67
67
|
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## v0.2.x (Experiment & Core Updates)
|
|
4
4
|
|
|
5
|
-
### **v0.2.
|
|
5
|
+
### **v0.2.31**
|
|
6
6
|
|
|
7
7
|
- ✨ **New Feature:**: add `common.common.log_func` as decorator to log function entry, exit, with execution time and arguments.
|
|
8
8
|
|
|
9
|
-
- 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `
|
|
9
|
+
- 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_exclude/include` and `prune` function
|
|
10
10
|
|
|
11
11
|
### **v0.2.28**
|
|
12
12
|
|
|
@@ -261,39 +261,50 @@ def pprint_local_path(
|
|
|
261
261
|
|
|
262
262
|
|
|
263
263
|
def log_func(
|
|
264
|
-
func: Optional[Callable] = None,
|
|
264
|
+
func: Optional[Callable] = None,
|
|
265
|
+
*,
|
|
266
|
+
log_time: bool = False,
|
|
267
|
+
log_args: bool = False,
|
|
268
|
+
skip_idxs: Optional[List[int]] = None, # New parameter
|
|
265
269
|
):
|
|
266
270
|
"""
|
|
267
|
-
|
|
268
|
-
Supports both @log_func and @log_func(log_time=True) usage.
|
|
271
|
+
Enhanced decorator that logs arguments line-by-line and allows skipping indices.
|
|
269
272
|
"""
|
|
270
|
-
# 1. HANDLE ARGUMENTS: If called as @log_func(log_time=True), func is None.
|
|
271
|
-
# We return a 'partial' function that remembers the args and waits for the func.
|
|
272
273
|
if func is None:
|
|
273
|
-
return functools.partial(
|
|
274
|
+
return functools.partial(
|
|
275
|
+
log_func, log_time=log_time, log_args=log_args, skip_idxs=skip_idxs
|
|
276
|
+
)
|
|
274
277
|
|
|
275
|
-
# 2. HANDLE DECORATION: If called as @log_func, func is the actual function.
|
|
276
278
|
@functools.wraps(func)
|
|
277
279
|
def wrapper(*args, **kwargs):
|
|
278
|
-
# Safe way to get name (handles partials/lambdas)
|
|
279
280
|
func_name = getattr(func, "__name__", "Unknown_Func")
|
|
281
|
+
skip_list = skip_idxs or []
|
|
280
282
|
|
|
281
|
-
# Note: Ensure 'ConsoleLog' context manager is available in your scope
|
|
282
283
|
with ConsoleLog(func_name):
|
|
283
284
|
start = time.perf_counter()
|
|
284
285
|
try:
|
|
285
286
|
result = func(*args, **kwargs)
|
|
286
287
|
finally:
|
|
287
|
-
# We use finally to ensure logging happens even if func crashes
|
|
288
288
|
end = time.perf_counter()
|
|
289
289
|
|
|
290
290
|
if log_time or log_args:
|
|
291
|
-
|
|
292
291
|
console.print(pad_string(f"Func <{func_name}> summary", 80))
|
|
292
|
+
|
|
293
|
+
if log_args:
|
|
294
|
+
console.print(f"--- Arguments for {func_name} ---")
|
|
295
|
+
# Log Positional Args line-by-line
|
|
296
|
+
for i, val in enumerate(args):
|
|
297
|
+
if i in skip_list:
|
|
298
|
+
console.print(f" arg[{i}]: <SKIPPED>")
|
|
299
|
+
continue
|
|
300
|
+
pprint(f" arg[{i}]: \n {val}")
|
|
301
|
+
|
|
302
|
+
# Log Keyword Args line-by-line
|
|
303
|
+
for k, v in kwargs.items():
|
|
304
|
+
pprint(f" {k}: \n {v}")
|
|
305
|
+
|
|
293
306
|
if log_time:
|
|
294
307
|
console.print(f"{func_name} took {end - start:.6f} seconds")
|
|
295
|
-
if log_args:
|
|
296
|
-
console.print(f"Args: {args}, Kwargs: {kwargs}")
|
|
297
308
|
|
|
298
309
|
return result
|
|
299
310
|
|
|
@@ -136,9 +136,9 @@ class DictUtils:
|
|
|
136
136
|
return full_hash[:length]
|
|
137
137
|
|
|
138
138
|
@staticmethod
|
|
139
|
-
def
|
|
139
|
+
def deep_exclude(
|
|
140
140
|
d: Dict[str, Any],
|
|
141
|
-
|
|
141
|
+
keys_to_exclude: List[str],
|
|
142
142
|
in_place: bool = False,
|
|
143
143
|
sep: str = ".",
|
|
144
144
|
) -> Dict[str, Any]:
|
|
@@ -147,7 +147,7 @@ class DictUtils:
|
|
|
147
147
|
|
|
148
148
|
Args:
|
|
149
149
|
d: The dictionary to filter.
|
|
150
|
-
|
|
150
|
+
keys_to_exclude: A list of flattened keys to exclude (e.g., ['model.layers.dropout']).
|
|
151
151
|
in_place: If True, modifies the dictionary directly.
|
|
152
152
|
If False, creates and modifies a deep copy, leaving the original untouched.
|
|
153
153
|
sep: Separator used in the dot-notation keys (default: ".").
|
|
@@ -157,7 +157,7 @@ class DictUtils:
|
|
|
157
157
|
|
|
158
158
|
Example:
|
|
159
159
|
>>> data = {'a': {'b': 1, 'c': 2}}
|
|
160
|
-
>>> DictUtils.
|
|
160
|
+
>>> DictUtils.deep_exclude(data, ['a.b'], in_place=False)
|
|
161
161
|
{'a': {'c': 2}}
|
|
162
162
|
"""
|
|
163
163
|
# 1. Handle the copy logic based on the in_place flag
|
|
@@ -167,7 +167,7 @@ class DictUtils:
|
|
|
167
167
|
target_dict = copy.deepcopy(d)
|
|
168
168
|
|
|
169
169
|
# 2. Iterate over each dot-notation key we want to delete
|
|
170
|
-
for flat_key in
|
|
170
|
+
for flat_key in keys_to_exclude:
|
|
171
171
|
parts = flat_key.split(sep)
|
|
172
172
|
|
|
173
173
|
# 3. Traverse to the parent container of the key we want to delete
|
|
@@ -191,6 +191,94 @@ class DictUtils:
|
|
|
191
191
|
|
|
192
192
|
return target_dict
|
|
193
193
|
|
|
194
|
+
@staticmethod
|
|
195
|
+
def deep_include(
|
|
196
|
+
d: Dict[str, Any],
|
|
197
|
+
keys_to_include: List[str],
|
|
198
|
+
in_place: bool = False,
|
|
199
|
+
sep: str = ".",
|
|
200
|
+
) -> Dict[str, Any]:
|
|
201
|
+
"""
|
|
202
|
+
Filters a nested dictionary to keep ONLY the specified dot-notation paths.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
d: The dictionary to filter.
|
|
206
|
+
keys_to_include: A list of flattened keys to include (e.g., ['a.b.c']).
|
|
207
|
+
in_place: If True, modifies the original dictionary.
|
|
208
|
+
sep: Separator used in the dot-notation keys.
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
The filtered dictionary.
|
|
212
|
+
"""
|
|
213
|
+
# 1. Create a fresh container for the keys we want to preserve
|
|
214
|
+
# Unlike deep_remove, it's often cleaner to build a new dict
|
|
215
|
+
# than to delete everything else.
|
|
216
|
+
new_dict = {}
|
|
217
|
+
|
|
218
|
+
for flat_key in keys_to_include:
|
|
219
|
+
parts = flat_key.split(sep)
|
|
220
|
+
|
|
221
|
+
# Pointers to traverse both dictionaries
|
|
222
|
+
current_source = d
|
|
223
|
+
current_target = new_dict
|
|
224
|
+
|
|
225
|
+
for i, part in enumerate(parts):
|
|
226
|
+
if isinstance(current_source, dict) and part in current_source:
|
|
227
|
+
# Move down the source
|
|
228
|
+
current_source = current_source[part]
|
|
229
|
+
|
|
230
|
+
# If we are at the leaf of the 'keep' path, copy the value
|
|
231
|
+
if i == len(parts) - 1:
|
|
232
|
+
current_target[part] = copy.deepcopy(current_source)
|
|
233
|
+
else:
|
|
234
|
+
# If the path doesn't exist in our new_dict yet, create it
|
|
235
|
+
if part not in current_target or not isinstance(
|
|
236
|
+
current_target[part], dict
|
|
237
|
+
):
|
|
238
|
+
current_target[part] = {}
|
|
239
|
+
current_target = current_target[part]
|
|
240
|
+
else:
|
|
241
|
+
# The path to keep doesn't exist in the source, skip it
|
|
242
|
+
break
|
|
243
|
+
|
|
244
|
+
# 2. Handle the in_place logic
|
|
245
|
+
if in_place:
|
|
246
|
+
d.clear()
|
|
247
|
+
d.update(new_dict)
|
|
248
|
+
return d
|
|
249
|
+
|
|
250
|
+
return new_dict
|
|
251
|
+
|
|
252
|
+
@staticmethod
|
|
253
|
+
def apply_exclusion_mask(
|
|
254
|
+
d: Dict[str, Any],
|
|
255
|
+
config_mask: Dict[str, Any],
|
|
256
|
+
in_place: bool = False,
|
|
257
|
+
sep: str = ".",
|
|
258
|
+
) -> Dict[str, Any]:
|
|
259
|
+
"""
|
|
260
|
+
Uses a dictionary 'mask' to define what to throw away.
|
|
261
|
+
"""
|
|
262
|
+
# Assuming your DictUtils.flatten returns a dict of {path: value}
|
|
263
|
+
flatten_dict = DictUtils.flatten(config_mask, sep=sep)
|
|
264
|
+
paths_to_exclude = list(flatten_dict.keys())
|
|
265
|
+
return DictUtils.deep_exclude(d, paths_to_exclude, in_place=in_place, sep=sep)
|
|
266
|
+
|
|
267
|
+
@staticmethod
|
|
268
|
+
def apply_inclusion_mask(
|
|
269
|
+
d: Dict[str, Any],
|
|
270
|
+
config_mask: Dict[str, Any],
|
|
271
|
+
in_place: bool = False,
|
|
272
|
+
sep: str = ".",
|
|
273
|
+
) -> Dict[str, Any]:
|
|
274
|
+
"""
|
|
275
|
+
Renamed from 'deep_keep_by_config'.
|
|
276
|
+
Uses a dictionary 'mask' to define what to allow.
|
|
277
|
+
"""
|
|
278
|
+
flatten_dict = DictUtils.flatten(config_mask, sep=sep)
|
|
279
|
+
paths_to_include = list(flatten_dict.keys())
|
|
280
|
+
return DictUtils.deep_include(d, paths_to_include, in_place=in_place, sep=sep)
|
|
281
|
+
|
|
194
282
|
@staticmethod
|
|
195
283
|
def prune(d: Any, prune_values: Tuple[Any, ...] = (None, {}, [], "")) -> Any:
|
|
196
284
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.31
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -57,11 +57,11 @@ Dynamic: summary
|
|
|
57
57
|
|
|
58
58
|
## v0.2.x (Experiment & Core Updates)
|
|
59
59
|
|
|
60
|
-
### **v0.2.
|
|
60
|
+
### **v0.2.31**
|
|
61
61
|
|
|
62
62
|
- ✨ **New Feature:**: add `common.common.log_func` as decorator to log function entry, exit, with execution time and arguments.
|
|
63
63
|
|
|
64
|
-
- 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `
|
|
64
|
+
- 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_exclude/include` and `prune` function
|
|
65
65
|
|
|
66
66
|
### **v0.2.28**
|
|
67
67
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|