thomasw21
commited on
Commit
·
ab01e28
1
Parent(s):
f6d6453
Perhaps that's better
Browse files
pmd.py
CHANGED
|
@@ -95,7 +95,7 @@ class DatasetsLoader(BaseLoader):
|
|
| 95 |
self.num_proc = num_proc
|
| 96 |
# In order to not have memory explode we define a batch size per proc
|
| 97 |
self.batch_size_per_proc = batch_size // self.num_proc
|
| 98 |
-
assert self.batch_size_per_proc
|
| 99 |
|
| 100 |
@abstractmethod
|
| 101 |
def cast_to_pmd_features(self, row: Dict) -> List[Dict[str, Any]]:
|
|
@@ -111,7 +111,7 @@ class DatasetsLoader(BaseLoader):
|
|
| 111 |
for i in range(batch_size)
|
| 112 |
]
|
| 113 |
|
| 114 |
-
def _generate_rows_casted_pmd_features(self,
|
| 115 |
dataset_size = len(dset)
|
| 116 |
batch_end = min(batch_start + self.batch_size_per_proc, dataset_size)
|
| 117 |
batch = dset[batch_start:batch_end]
|
|
@@ -138,7 +138,7 @@ class DatasetsLoader(BaseLoader):
|
|
| 138 |
assert self.num_proc > 1
|
| 139 |
with Pool(self.num_proc) as pool:
|
| 140 |
rows_casted_pmd_features = pool.imap(
|
| 141 |
-
partial(self._generate_rows_casted_pmd_features, dataset),
|
| 142 |
range(0, dataset_size, self.batch_size_per_proc),
|
| 143 |
)
|
| 144 |
for row_casted_pmd_features in rows_casted_pmd_features:
|
|
|
|
| 95 |
self.num_proc = num_proc
|
| 96 |
# In order to not have memory explode we define a batch size per proc
|
| 97 |
self.batch_size_per_proc = batch_size // self.num_proc
|
| 98 |
+
assert self.batch_size_per_proc >= 1
|
| 99 |
|
| 100 |
@abstractmethod
|
| 101 |
def cast_to_pmd_features(self, row: Dict) -> List[Dict[str, Any]]:
|
|
|
|
| 111 |
for i in range(batch_size)
|
| 112 |
]
|
| 113 |
|
| 114 |
+
def _generate_rows_casted_pmd_features(self, batch_start: int, dset: Dataset):
|
| 115 |
dataset_size = len(dset)
|
| 116 |
batch_end = min(batch_start + self.batch_size_per_proc, dataset_size)
|
| 117 |
batch = dset[batch_start:batch_end]
|
|
|
|
| 138 |
assert self.num_proc > 1
|
| 139 |
with Pool(self.num_proc) as pool:
|
| 140 |
rows_casted_pmd_features = pool.imap(
|
| 141 |
+
partial(self._generate_rows_casted_pmd_features, dset=dataset),
|
| 142 |
range(0, dataset_size, self.batch_size_per_proc),
|
| 143 |
)
|
| 144 |
for row_casted_pmd_features in rows_casted_pmd_features:
|