MCPcopy Create free account
hub / github.com/InternScience/SciReason / partition

Method partition

opencompass/partitioners/size.py:53–136  ·  view source on GitHub ↗

Partition model-dataset pairs into tasks. Each task is defined as a dict and will run independently as a unit. Its structure is as follows: .. code-block:: python { 'models': [], # a list of model configs 'datasets': [[]], # a n

(self,
                  model_dataset_combinations: List[Dict[str,
                                                        List[ConfigDict]]],
                  work_dir: str,
                  out_dir: str,
                  add_cfg: Dict = {})

Source from the content-addressed store, hash-verified

51 self.strategy = strategy
52
53 def partition(self,
54 model_dataset_combinations: List[Dict[str,
55 List[ConfigDict]]],
56 work_dir: str,
57 out_dir: str,
58 add_cfg: Dict = {}) -> List[ConfigDict]:
59 """Partition model-dataset pairs into tasks. Each task is defined as a
60 dict and will run independently as a unit. Its structure is as
61 follows:
62
63 .. code-block:: python
64
65 {
66 'models': [], # a list of model configs
67 'datasets': [[]], # a nested list of dataset configs, each
68 list corresponds to a model
69 'work_dir': '', # the work dir
70 **add_cfg # other keys to be kept in the config
71 }
72
73 Args:
74 model_dataset_combinations (List[Dict]): List of
75 `{models: [...], datasets: [...]}` dicts. Each dict contains
76 a list of model configs and a list of dataset configs.
77 work_dir (str): The work dir for the task.
78 out_dir (str): The full output path for the task, intended for
79 Partitioners to check whether the task is finished via the
80 existency of result file in this directory.
81 add_cfg (dict): Other common keys to be added in the task config,
82 used to share the same config among tasks. Defaults to {}.
83
84 Returns:
85 List[ConfigDict]: A list of tasks.
86 """
87
88 tasks = []
89 for comb in model_dataset_combinations:
90 comb['datasets'] = sorted(comb['datasets'],
91 key=lambda x: self.get_cost(x),
92 reverse=True)
93 for model in comb['models']:
94 chunks = [] # elements: tuple(size, dataset_chunk)
95 for dataset in comb['datasets']:
96 filename = get_infer_output_path(model, dataset, out_dir)
97 # skip the task if the task output exists
98 if osp.exists(filename):
99 continue
100 dataset_size = self.get_cost(dataset)
101 if dataset_size > self.max_task_size:
102 root, ext = osp.splitext(filename)
103 dataset_splits = self.split_dataset(dataset)
104 for i, dataset_split in enumerate(dataset_splits):
105 if not osp.exists(f'{root}_{i}{ext}'):
106 chunks.append(
107 (self.max_task_size, dataset_split))
108 else:
109 chunks.append((dataset_size, dataset))
110

Callers

nothing calls this directly

Calls 4

get_costMethod · 0.95
split_datasetMethod · 0.95
get_infer_output_pathFunction · 0.90
ConfigClass · 0.50

Tested by

no test coverage detected