Hide GPUs before spawning TensorFlow data workers by jinchuntan · Pull Request #8847 · huggingface/datasets · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/datasets/utils/tf_utils.py
16 changes: 16 additions & 0 deletions tests/fixtures/tf_initialized_collate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

import numpy as np
import tensorflow as tf


# Importing a user's collator can initialize TensorFlow before the worker target runs.
IMPORT_TIME_TENSOR = tf.constant(1, dtype=tf.int64)
GPUS_HIDDEN_AT_IMPORT = os.environ.get("CUDA_VISIBLE_DEVICES") == "" and not tf.config.get_visible_devices("GPU")


def collate_with_initialized_tensorflow(examples):
return {
"x": tf.convert_to_tensor([example["x"] for example in examples], dtype=tf.int64) * IMPORT_TIME_TENSOR,
"gpus_hidden_at_import": np.full(len(examples), GPUS_HIDDEN_AT_IMPORT),
}
64 changes: 64 additions & 0 deletions tests/test_tf_utils.py