Skip to content

Commit

Permalink
Upgrade tool_helpers to support 32766个dataset. (PaddlePaddle#8994)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunnYu committed Aug 23, 2024
1 parent 3e87308 commit abbe4df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions model_zoo/ernie-1.0/data_tools/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace std;

const int32_t LONG_SENTENCE_LEN = 512;

void build_blending_indices(py::array_t<uint8_t>& dataset_index,
void build_blending_indices(py::array_t<int16_t>& dataset_index,
py::array_t<int64_t>& dataset_sample_index,
const py::array_t<double>& weights,
const int32_t num_datasets,
Expand Down Expand Up @@ -73,7 +73,7 @@ void build_blending_indices(py::array_t<uint8_t>& dataset_index,
}

// Populate the indices.
dataset_index_ptr[sample_idx] = static_cast<uint8_t>(max_error_index);
dataset_index_ptr[sample_idx] = static_cast<int16_t>(max_error_index);
dataset_sample_index_ptr[sample_idx] = current_samples[max_error_index];

// Update the total samples.
Expand Down
15 changes: 13 additions & 2 deletions paddlenlp/data/blendable_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import hashlib
import importlib.metadata
import os
import time

Expand Down Expand Up @@ -45,8 +46,18 @@ def __init__(self, datasets, weights, size, share_folder, *, data_cache_path=Non
# Build indicies.
def _build_indices():
start_time = time.time()
assert num_datasets < 255
dataset_index = np.zeros(self.size, dtype=np.uint8)

tool_helpers_version = importlib.metadata.version("tool_helpers")
if tool_helpers_version > "0.1.1":
assert (
num_datasets < 32767
), f"Detect num_datasets({num_datasets})>=32767. Currently, num_datasets should be less than 32767."
dataset_index = np.zeros(self.size, dtype=np.int16)
else:
assert (
num_datasets < 255
), f"Detect num_datasets:({num_datasets})>=255. When 'tool_helpers<=0.1.1', num_datasets should be less than 255. To support num_datasets greater than 255, please upgrade `tool_helpers>=0.1.2`."
dataset_index = np.zeros(self.size, dtype=np.uint8)
dataset_sample_index = np.zeros(self.size, dtype=np.int64)

from tool_helpers import helpers
Expand Down

0 comments on commit abbe4df

Please sign in to comment.