fusion-bench 0.2.21__py3-none-any.whl → 0.2.22__py3-none-any.whl
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.
- fusion_bench/__init__.py +21 -2
- fusion_bench/constants/__init__.py +1 -0
- fusion_bench/constants/runtime.py +57 -0
- fusion_bench/method/__init__.py +8 -2
- fusion_bench/method/bitdelta/__init__.py +1 -0
- fusion_bench/method/classification/clip_finetune.py +1 -1
- fusion_bench/method/fisher_merging/clip_fisher_merging.py +0 -4
- fusion_bench/method/fisher_merging/gpt2_fisher_merging.py +2 -2
- fusion_bench/method/linear/simple_average_for_llama.py +16 -11
- fusion_bench/method/simple_average.py +7 -7
- fusion_bench/method/smile_upscaling/causal_lm_upscaling.py +371 -0
- fusion_bench/method/smile_upscaling/projected_energy.py +1 -2
- fusion_bench/method/smile_upscaling/smile_mistral_upscaling.py +5 -1
- fusion_bench/method/smile_upscaling/smile_qwen2_upscaling.py +40 -31
- fusion_bench/method/smile_upscaling/smile_upscaling.py +1 -1
- fusion_bench/method/we_moe/__init__.py +1 -0
- fusion_bench/method/we_moe/entropy_loss.py +25 -0
- fusion_bench/method/we_moe/flan_t5_we_moe.py +331 -0
- fusion_bench/method/we_moe/utils.py +15 -0
- fusion_bench/method/weighted_average/llama.py +1 -1
- fusion_bench/mixins/clip_classification.py +11 -42
- fusion_bench/mixins/serialization.py +18 -8
- fusion_bench/modelpool/causal_lm/causal_lm.py +32 -33
- fusion_bench/models/__init__.py +5 -0
- fusion_bench/models/hf_utils.py +65 -87
- fusion_bench/models/model_card_templates/default.md +46 -0
- fusion_bench/models/modeling_smile_llama/__init__.py +7 -0
- fusion_bench/models/modeling_smile_llama/modeling_smile_llama.py +1 -8
- fusion_bench/models/modeling_smile_mistral/__init__.py +1 -1
- fusion_bench/models/modeling_smile_qwen2/modeling_smile_qwen2.py +1 -5
- fusion_bench/programs/fabric_fusion_program.py +29 -60
- fusion_bench/scripts/cli.py +34 -1
- fusion_bench/taskpool/clip_vision/taskpool.py +9 -4
- fusion_bench/utils/__init__.py +1 -0
- fusion_bench/utils/cache_utils.py +101 -1
- fusion_bench/utils/fabric.py +2 -2
- fusion_bench/utils/lazy_imports.py +23 -0
- fusion_bench/utils/lazy_state_dict.py +38 -3
- fusion_bench/utils/modelscope.py +3 -3
- fusion_bench/utils/path.py +56 -0
- fusion_bench/utils/pylogger.py +1 -1
- {fusion_bench-0.2.21.dist-info → fusion_bench-0.2.22.dist-info}/METADATA +1 -23
- {fusion_bench-0.2.21.dist-info → fusion_bench-0.2.22.dist-info}/RECORD +53 -45
- fusion_bench_config/method/fisher_merging/clip_fisher_merging.yaml +0 -1
- fusion_bench_config/method/linear/simple_average_for_llama.yaml +3 -2
- fusion_bench_config/method/smile_upscaling/causal_lm_upscaling.yaml +21 -0
- fusion_bench_config/method/smile_upscaling/smile_qwen2_upscaling.yaml +1 -1
- fusion_bench_config/method/wemoe/flan_t5_weight_ensembling_moe.yaml +20 -0
- fusion_bench_config/modelpool/CausalLMPool/Qwen2.5-1.5B_math_and_coder.yaml +1 -1
- {fusion_bench-0.2.21.dist-info → fusion_bench-0.2.22.dist-info}/WHEEL +0 -0
- {fusion_bench-0.2.21.dist-info → fusion_bench-0.2.22.dist-info}/entry_points.txt +0 -0
- {fusion_bench-0.2.21.dist-info → fusion_bench-0.2.22.dist-info}/licenses/LICENSE +0 -0
- {fusion_bench-0.2.21.dist-info → fusion_bench-0.2.22.dist-info}/top_level.txt +0 -0
fusion_bench/scripts/cli.py
CHANGED
|
@@ -12,9 +12,9 @@ import os
|
|
|
12
12
|
import hydra
|
|
13
13
|
from omegaconf import DictConfig, OmegaConf
|
|
14
14
|
|
|
15
|
+
from fusion_bench.constants import PROJECT_ROOT_PATH
|
|
15
16
|
from fusion_bench.programs import BaseHydraProgram
|
|
16
17
|
from fusion_bench.utils import instantiate
|
|
17
|
-
from fusion_bench.constants import PROJECT_ROOT_PATH
|
|
18
18
|
|
|
19
19
|
log = logging.getLogger(__name__)
|
|
20
20
|
|
|
@@ -34,6 +34,39 @@ def _get_default_config_path():
|
|
|
34
34
|
version_base=None,
|
|
35
35
|
)
|
|
36
36
|
def main(cfg: DictConfig) -> None:
|
|
37
|
+
"""
|
|
38
|
+
Main entry point for the FusionBench command-line interface.
|
|
39
|
+
|
|
40
|
+
This function serves as the primary entry point for the `fusion_bench` CLI command.
|
|
41
|
+
It is decorated with Hydra's main decorator to handle configuration management,
|
|
42
|
+
command-line argument parsing, and configuration file loading.
|
|
43
|
+
|
|
44
|
+
The function performs the following operations:
|
|
45
|
+
1. Resolves any interpolations in the configuration using OmegaConf
|
|
46
|
+
2. Instantiates the appropriate program class based on the configuration
|
|
47
|
+
3. Executes the program's run method to perform the fusion task
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
cfg (DictConfig): The Hydra configuration object containing all settings
|
|
51
|
+
for the fusion task. This includes method configuration, model pool
|
|
52
|
+
configuration, task pool configuration, and other runtime parameters.
|
|
53
|
+
The configuration is automatically loaded by Hydra from the specified
|
|
54
|
+
config files and command-line overrides.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
None: This function doesn't return a value but executes the fusion
|
|
58
|
+
program which may save results, log outputs, or perform other
|
|
59
|
+
side effects as configured.
|
|
60
|
+
|
|
61
|
+
Example:
|
|
62
|
+
This function is typically called automatically when running:
|
|
63
|
+
```bash
|
|
64
|
+
fusion_bench method=... modelpool=... taskpool=...
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The Hydra decorator handles parsing these command-line arguments and
|
|
68
|
+
loading the corresponding configuration files to populate the cfg parameter.
|
|
69
|
+
"""
|
|
37
70
|
OmegaConf.resolve(cfg)
|
|
38
71
|
program: BaseHydraProgram = instantiate(cfg)
|
|
39
72
|
program.run()
|
|
@@ -27,8 +27,9 @@ from tqdm.autonotebook import tqdm
|
|
|
27
27
|
from transformers import CLIPModel, CLIPProcessor, CLIPVisionModel
|
|
28
28
|
from transformers.models.clip.modeling_clip import CLIPVisionTransformer
|
|
29
29
|
|
|
30
|
+
from fusion_bench import RuntimeConstants
|
|
30
31
|
from fusion_bench.dataset import CLIPDataset
|
|
31
|
-
from fusion_bench.mixins import LightningFabricMixin
|
|
32
|
+
from fusion_bench.mixins import HydraConfigMixin, LightningFabricMixin
|
|
32
33
|
from fusion_bench.models.hf_clip import HFCLIPClassifier
|
|
33
34
|
from fusion_bench.taskpool import BaseTaskPool
|
|
34
35
|
from fusion_bench.tasks.clip_classification import get_classnames_and_templates
|
|
@@ -86,8 +87,9 @@ class LayerWiseFeatureSaver:
|
|
|
86
87
|
|
|
87
88
|
|
|
88
89
|
class CLIPVisionModelTaskPool(
|
|
89
|
-
|
|
90
|
+
HydraConfigMixin,
|
|
90
91
|
LightningFabricMixin,
|
|
92
|
+
BaseTaskPool,
|
|
91
93
|
):
|
|
92
94
|
"""
|
|
93
95
|
This class is used to define the image classification task for CLIP models.
|
|
@@ -131,7 +133,7 @@ class CLIPVisionModelTaskPool(
|
|
|
131
133
|
layer_wise_feature_save_path: Optional[str] = None,
|
|
132
134
|
layer_wise_feature_first_token_only: bool = True,
|
|
133
135
|
layer_wise_feature_max_num: Optional[int] = None,
|
|
134
|
-
fast_dev_run: bool =
|
|
136
|
+
fast_dev_run: Optional[bool] = None,
|
|
135
137
|
**kwargs,
|
|
136
138
|
):
|
|
137
139
|
"""
|
|
@@ -153,7 +155,10 @@ class CLIPVisionModelTaskPool(
|
|
|
153
155
|
self.layer_wise_feature_first_token_only = layer_wise_feature_first_token_only
|
|
154
156
|
self.layer_wise_feature_max_num = layer_wise_feature_max_num
|
|
155
157
|
|
|
156
|
-
self.fast_dev_run
|
|
158
|
+
if self.fast_dev_run is None:
|
|
159
|
+
self.fast_dev_run = RuntimeConstants().debug
|
|
160
|
+
else:
|
|
161
|
+
self.fast_dev_run = fast_dev_run
|
|
157
162
|
super().__init__(**kwargs)
|
|
158
163
|
|
|
159
164
|
def setup(self):
|
fusion_bench/utils/__init__.py
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
3
|
import pickle
|
|
4
|
+
import warnings
|
|
4
5
|
from functools import wraps
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import Any, Callable, Union
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
from joblib import Memory
|
|
10
|
+
|
|
11
|
+
__all__ = ["cache_to_disk", "cache_with_joblib", "set_default_cache_dir"]
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
log = logging.getLogger(__name__)
|
|
12
15
|
|
|
16
|
+
DEFAULT_CACHE_DIR = Path.cwd() / "outputs" / "cache"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def set_default_cache_dir(path: str | Path):
|
|
20
|
+
global DEFAULT_CACHE_DIR
|
|
21
|
+
if path is None:
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
if isinstance(path, str):
|
|
25
|
+
path = Path(path)
|
|
26
|
+
DEFAULT_CACHE_DIR = path
|
|
27
|
+
|
|
13
28
|
|
|
14
29
|
def cache_to_disk(file_path: Union[str, Path]) -> Callable:
|
|
15
30
|
"""
|
|
@@ -17,6 +32,11 @@ def cache_to_disk(file_path: Union[str, Path]) -> Callable:
|
|
|
17
32
|
the result is loaded from the file. Otherwise, the function is executed and
|
|
18
33
|
the result is saved to the file.
|
|
19
34
|
|
|
35
|
+
!!! warning "deprecated"
|
|
36
|
+
This function is deprecated. Use `cache_with_joblib` instead for better
|
|
37
|
+
caching capabilities including automatic cache invalidation, better object
|
|
38
|
+
handling, and memory efficiency.
|
|
39
|
+
|
|
20
40
|
## Example usage
|
|
21
41
|
|
|
22
42
|
```python
|
|
@@ -32,6 +52,13 @@ def cache_to_disk(file_path: Union[str, Path]) -> Callable:
|
|
|
32
52
|
Returns:
|
|
33
53
|
Callable: The decorated function.
|
|
34
54
|
"""
|
|
55
|
+
warnings.warn(
|
|
56
|
+
"cache_to_disk is deprecated. Use cache_with_joblib instead for better "
|
|
57
|
+
"caching capabilities including automatic cache invalidation, better object "
|
|
58
|
+
"handling, and memory efficiency.",
|
|
59
|
+
DeprecationWarning,
|
|
60
|
+
stacklevel=2,
|
|
61
|
+
)
|
|
35
62
|
if isinstance(file_path, str):
|
|
36
63
|
file_path = Path(file_path)
|
|
37
64
|
assert isinstance(file_path, Path)
|
|
@@ -56,3 +83,76 @@ def cache_to_disk(file_path: Union[str, Path]) -> Callable:
|
|
|
56
83
|
return wrapper
|
|
57
84
|
|
|
58
85
|
return decorator
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def cache_with_joblib(
|
|
89
|
+
cache_dir: Union[str, Path] = None,
|
|
90
|
+
verbose: int = 0,
|
|
91
|
+
) -> Callable:
|
|
92
|
+
"""
|
|
93
|
+
A decorator to cache the result of a function using joblib.Memory. This provides
|
|
94
|
+
more advanced caching capabilities compared to cache_to_disk, including:
|
|
95
|
+
- Automatic cache invalidation when function arguments change
|
|
96
|
+
- Better handling of numpy arrays and other complex objects
|
|
97
|
+
- Memory-efficient storage
|
|
98
|
+
- Optional verbose output for cache hits/misses
|
|
99
|
+
|
|
100
|
+
## Example usage
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
@cache_with_joblib("./cache", verbose=1)
|
|
104
|
+
def expensive_computation(x: int, y: str) -> Any:
|
|
105
|
+
# Function implementation
|
|
106
|
+
return complex_result
|
|
107
|
+
|
|
108
|
+
# Or with default settings:
|
|
109
|
+
@cache_with_joblib()
|
|
110
|
+
def another_function(x: int) -> int:
|
|
111
|
+
return x * 2
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
cache_dir (Union[str, Path]): The directory where cache files should be stored.
|
|
116
|
+
If `None`, a default directory `outputs/cache` will be used.
|
|
117
|
+
verbose (int): Verbosity level for joblib.Memory (0=silent, 1=basic, 2++=verbose).
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
Callable: A decorator function that can be applied to functions.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
if cache_dir is None:
|
|
124
|
+
cache_dir = DEFAULT_CACHE_DIR
|
|
125
|
+
|
|
126
|
+
if isinstance(cache_dir, str):
|
|
127
|
+
cache_dir = Path(cache_dir)
|
|
128
|
+
assert isinstance(cache_dir, Path)
|
|
129
|
+
|
|
130
|
+
# Create the cache directory if it doesn't exist
|
|
131
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
132
|
+
|
|
133
|
+
# Create a Memory object for this function
|
|
134
|
+
memory = Memory(location=cache_dir, verbose=verbose)
|
|
135
|
+
|
|
136
|
+
def decorator(func: Callable) -> Callable:
|
|
137
|
+
nonlocal memory
|
|
138
|
+
|
|
139
|
+
# Create the cached version of the function
|
|
140
|
+
cached_func = memory.cache(func)
|
|
141
|
+
|
|
142
|
+
@wraps(func)
|
|
143
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
144
|
+
return cached_func(*args, **kwargs)
|
|
145
|
+
|
|
146
|
+
# Expose useful methods from joblib.Memory
|
|
147
|
+
if not (
|
|
148
|
+
hasattr(cached_func, "clear")
|
|
149
|
+
or hasattr(cached_func, "call")
|
|
150
|
+
or hasattr(cached_func, "check_call_in_cache")
|
|
151
|
+
):
|
|
152
|
+
wrapper.clear = cached_func.clear
|
|
153
|
+
wrapper.call = cached_func.call
|
|
154
|
+
wrapper.check_call_in_cache = cached_func.check_call_in_cache
|
|
155
|
+
|
|
156
|
+
return wrapper
|
|
157
|
+
|
|
158
|
+
return decorator
|
fusion_bench/utils/fabric.py
CHANGED
|
@@ -3,9 +3,9 @@ from typing import Optional
|
|
|
3
3
|
|
|
4
4
|
import lightning as L
|
|
5
5
|
|
|
6
|
-
from fusion_bench.utils.pylogger import
|
|
6
|
+
from fusion_bench.utils.pylogger import get_rankzero_logger
|
|
7
7
|
|
|
8
|
-
log =
|
|
8
|
+
log = get_rankzero_logger(__name__)
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def seed_everything_by_time(fabric: Optional[L.Fabric] = None):
|
|
@@ -72,3 +72,26 @@ class LazyImporter(ModuleType):
|
|
|
72
72
|
|
|
73
73
|
def __reduce__(self):
|
|
74
74
|
return (self.__class__, (self._name, self.__file__, self._import_structure))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class LazyModule(ModuleType):
|
|
78
|
+
"""Module wrapper for lazy import.
|
|
79
|
+
Adapted from Optuna: https://github.com/optuna/optuna/blob/1f92d496b0c4656645384e31539e4ee74992ff55/optuna/__init__.py
|
|
80
|
+
|
|
81
|
+
This class wraps specified module and lazily import it when they are actually accessed.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
name: Name of module to apply lazy import.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
def __init__(self, name: str) -> None:
|
|
88
|
+
super().__init__(name)
|
|
89
|
+
self._name = name
|
|
90
|
+
|
|
91
|
+
def _load(self) -> ModuleType:
|
|
92
|
+
module = importlib.import_module(self._name)
|
|
93
|
+
self.__dict__.update(module.__dict__)
|
|
94
|
+
return module
|
|
95
|
+
|
|
96
|
+
def __getattr__(self, item: str) -> Any:
|
|
97
|
+
return getattr(self._load(), item)
|
|
@@ -2,7 +2,7 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
import os
|
|
4
4
|
from copy import deepcopy
|
|
5
|
-
from typing import TYPE_CHECKING, Dict, Iterator, List, Optional, Tuple, Type
|
|
5
|
+
from typing import TYPE_CHECKING, Dict, Iterator, List, Mapping, Optional, Tuple, Type
|
|
6
6
|
|
|
7
7
|
import torch
|
|
8
8
|
from accelerate import init_empty_weights
|
|
@@ -49,7 +49,7 @@ def resolve_checkpoint_path(
|
|
|
49
49
|
)
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
class LazyStateDict:
|
|
52
|
+
class LazyStateDict(Mapping[str, torch.Tensor]):
|
|
53
53
|
"""
|
|
54
54
|
Dictionary-like object that lazily loads a state dict from a checkpoint path.
|
|
55
55
|
"""
|
|
@@ -168,12 +168,21 @@ class LazyStateDict:
|
|
|
168
168
|
def config(self) -> "PretrainedConfig":
|
|
169
169
|
return AutoConfig.from_pretrained(self._checkpoint)
|
|
170
170
|
|
|
171
|
+
@property
|
|
172
|
+
def dtype(self) -> torch.dtype:
|
|
173
|
+
"""
|
|
174
|
+
`torch.dtype`: The dtype of the module (assuming that all the module parameters have the same dtype).
|
|
175
|
+
"""
|
|
176
|
+
first_key = next(iter(self.keys()))
|
|
177
|
+
first_param = self[first_key]
|
|
178
|
+
return first_param.dtype
|
|
179
|
+
|
|
171
180
|
def state_dict(self, keep_vars: bool = False) -> "LazyStateDict":
|
|
172
181
|
"""
|
|
173
182
|
Args:
|
|
174
183
|
keep_vars (bool): Ignored, as LazyStateDict does not support keep_vars. Just for compatibility.
|
|
175
184
|
"""
|
|
176
|
-
return self
|
|
185
|
+
return deepcopy(self)
|
|
177
186
|
|
|
178
187
|
def _resolve_checkpoint_files(self, checkpoint: str):
|
|
179
188
|
# reference: https://huggingface.co/docs/accelerate/v0.17.1/en/usage_guides/big_modeling
|
|
@@ -290,6 +299,18 @@ class LazyStateDict:
|
|
|
290
299
|
)
|
|
291
300
|
return tensor
|
|
292
301
|
|
|
302
|
+
def pop(self, key: str):
|
|
303
|
+
assert key in list(
|
|
304
|
+
self.keys()
|
|
305
|
+
), "KeyError: Cannot pop a tensor for a key that does not exist in the LazyStateDict."
|
|
306
|
+
if self._state_dict_cache is not None and key in self._state_dict_cache:
|
|
307
|
+
if key in self._index:
|
|
308
|
+
self._index.pop(key)
|
|
309
|
+
return self._state_dict_cache.pop(key)
|
|
310
|
+
if key in self._index:
|
|
311
|
+
self._index.pop(key)
|
|
312
|
+
return None
|
|
313
|
+
|
|
293
314
|
def __setitem__(self, key: str, value: torch.Tensor) -> None:
|
|
294
315
|
"""
|
|
295
316
|
Set a tensor in the LazyStateDict. This will update the state dict cache if it is enabled.
|
|
@@ -408,3 +429,17 @@ class LazyStateDict:
|
|
|
408
429
|
raise KeyError(f"Key {key} not found in LazyStateDict.")
|
|
409
430
|
for key, value in state_dict.items():
|
|
410
431
|
self[key] = value
|
|
432
|
+
|
|
433
|
+
def __getattr__(self, name: str):
|
|
434
|
+
if "meta_module" in self.__dict__:
|
|
435
|
+
meta_module = self.__dict__["meta_module"]
|
|
436
|
+
if meta_module is not None:
|
|
437
|
+
if "_parameters" in meta_module.__dict__:
|
|
438
|
+
if name in meta_module.__dict__["_parameters"]:
|
|
439
|
+
return self.get_parameter(name)
|
|
440
|
+
if "_modules" in meta_module.__dict__:
|
|
441
|
+
if name in meta_module.__dict__["_modules"]:
|
|
442
|
+
return self.get_submodule(name)
|
|
443
|
+
raise AttributeError(
|
|
444
|
+
f"'{type(self).__name__}' object has no attribute '{name}'"
|
|
445
|
+
)
|
fusion_bench/utils/modelscope.py
CHANGED
|
@@ -26,13 +26,13 @@ try:
|
|
|
26
26
|
from huggingface_hub import snapshot_download as huggingface_snapshot_download
|
|
27
27
|
except ImportError:
|
|
28
28
|
|
|
29
|
-
def
|
|
29
|
+
def _raise_huggingface_not_installed_error(*args, **kwargs):
|
|
30
30
|
raise ImportError(
|
|
31
31
|
"Hugging Face Hub is not installed. Please install it using `pip install huggingface_hub` to use Hugging Face models."
|
|
32
32
|
)
|
|
33
33
|
|
|
34
|
-
huggingface_snapshot_download =
|
|
35
|
-
hf_hub_download =
|
|
34
|
+
huggingface_snapshot_download = _raise_huggingface_not_installed_error
|
|
35
|
+
hf_hub_download = _raise_huggingface_not_installed_error
|
|
36
36
|
|
|
37
37
|
__all__ = [
|
|
38
38
|
"load_dataset",
|
fusion_bench/utils/path.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import os
|
|
2
3
|
from typing import List
|
|
3
4
|
|
|
5
|
+
log = logging.getLogger(__name__)
|
|
6
|
+
|
|
4
7
|
|
|
5
8
|
def path_is_dir_and_not_empty(path: str):
|
|
6
9
|
if path is None:
|
|
@@ -20,3 +23,56 @@ def listdir_fullpath(dir: str) -> List[str]:
|
|
|
20
23
|
assert os.path.isdir(dir), "Argument 'dir' must be a Directory"
|
|
21
24
|
names = os.listdir(dir)
|
|
22
25
|
return [os.path.join(dir, name) for name in names]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def create_symlink(src_dir: str, dst_dir: str, link_name: str = None):
|
|
29
|
+
"""
|
|
30
|
+
Creates a symbolic link from src_dir to dst_dir.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
src_dir (str): The source directory to link to.
|
|
34
|
+
dst_dir (str): The destination directory where the symlink will be created.
|
|
35
|
+
link_name (str, optional): The name of the symlink. If None, uses the basename of src_dir.
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
OSError: If the symbolic link creation fails.
|
|
39
|
+
ValueError: If src_dir does not exist or is not a directory.
|
|
40
|
+
"""
|
|
41
|
+
if not os.path.exists(src_dir):
|
|
42
|
+
raise ValueError(f"Source directory does not exist: {src_dir}")
|
|
43
|
+
|
|
44
|
+
if not os.path.isdir(src_dir):
|
|
45
|
+
raise ValueError(f"Source path is not a directory: {src_dir}")
|
|
46
|
+
|
|
47
|
+
# Avoid creating symlink if source and destination are the same
|
|
48
|
+
if os.path.abspath(src_dir) == os.path.abspath(dst_dir):
|
|
49
|
+
log.warning(
|
|
50
|
+
"Source and destination directories are the same, skipping symlink creation"
|
|
51
|
+
)
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
# Create destination directory if it doesn't exist
|
|
55
|
+
os.makedirs(dst_dir, exist_ok=True)
|
|
56
|
+
|
|
57
|
+
# Determine link name
|
|
58
|
+
if link_name is None:
|
|
59
|
+
link_name = os.path.basename(src_dir)
|
|
60
|
+
|
|
61
|
+
link_path = os.path.join(dst_dir, link_name)
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
# if the system is windows, use the `mklink` command in "CMD" to create the symlink
|
|
65
|
+
if os.name == "nt":
|
|
66
|
+
os.system(
|
|
67
|
+
f"mklink /J {os.path.abspath(link_path)} {os.path.abspath(src_dir)}"
|
|
68
|
+
)
|
|
69
|
+
else:
|
|
70
|
+
os.symlink(
|
|
71
|
+
src_dir,
|
|
72
|
+
link_path,
|
|
73
|
+
target_is_directory=True,
|
|
74
|
+
)
|
|
75
|
+
log.info(f"Created symbolic link: {link_path} -> {src_dir}")
|
|
76
|
+
except OSError as e:
|
|
77
|
+
log.warning(f"Failed to create symbolic link: {e}")
|
|
78
|
+
raise
|
fusion_bench/utils/pylogger.py
CHANGED
|
@@ -74,7 +74,7 @@ RankZeroLogger.manager = logging.Manager(RankZeroLogger.root)
|
|
|
74
74
|
RankZeroLogger.manager.setLoggerClass(RankZeroLogger)
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def
|
|
77
|
+
def get_rankzero_logger(name=None):
|
|
78
78
|
"""
|
|
79
79
|
Return a logger with the specified name, creating it if necessary.
|
|
80
80
|
|
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fusion_bench
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.22
|
|
4
4
|
Summary: A Comprehensive Benchmark of Deep Model Fusion
|
|
5
5
|
Author-email: Anke Tang <tang.anke@foxmail.com>
|
|
6
|
-
License: MIT License
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2024 Anke Tang
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
|
|
28
6
|
Project-URL: Repository, https://github.com/tanganke/fusion_bench
|
|
29
7
|
Project-URL: Homepage, https://github.com/tanganke/fusion_bench
|
|
30
8
|
Project-URL: Issues, https://github.com/tanganke/fusion_bench/issues
|