Skip to content

Commit

Permalink
deuglify mnist example
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 688971920
  • Loading branch information
Qwlouse authored and The kauldron Authors committed Oct 23, 2024
1 parent b598bef commit 87f7474
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions examples/mnist_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def get_config():


def _make_ds(training: bool):
Tfds = kd.data.py.Tfds
return Tfds(
return kd.data.py.Tfds(
name="mnist",
split="train" if training else "test",
shuffle=True if training else False,
Expand Down
2 changes: 1 addition & 1 deletion kauldron/data/py/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def ds_for_current_process(self, rng: random.PRNGKey) -> grain.MapDataset:

def _get_num_workers(num_workers: int) -> int:
"""Set the number of workers."""
if epy.is_notebook(): # in colab worker_count has to be 0
if epy.is_notebook() or epy.is_test(): # in colab worker_count has to be 0
# TODO(klausg): autodetect if Kernel supports multiprocessing
# Could check
# from multiprocessing import spawn
Expand Down
6 changes: 3 additions & 3 deletions kauldron/evals/eval_impl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test."""

from collections.abc import Iterator
import os
from unittest import mock
Expand All @@ -28,7 +26,9 @@ def test_eval_impl(tmp_path: epath.Path):
# Load config and reduce size
cfg = mnist_autoencoder.get_config()

cfg.train_ds.batch_size = 2
# TODO(klausg): remove this once data mocking works correctly with grain
cfg.train_ds.__qualname__ = 'kauldron.kd:data.Tfds'
cfg.train_ds.batch_size = 1
cfg.evals.eval.ds.batch_size = 1 # pytype: disable=attribute-error
cfg.model.encoder.features = 3
cfg.num_train_steps = 1
Expand Down
6 changes: 3 additions & 3 deletions kauldron/utils/sharding_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test."""

import os

from etils import epath
Expand All @@ -28,7 +26,9 @@ def test_sharding(tmp_path: epath.Path):
# Load config and reduce size
cfg = mnist_autoencoder.get_config()

cfg.train_ds.batch_size = 2
# TODO(klausg): remove this once data mocking works correctly with grain
cfg.train_ds.__qualname__ = 'kauldron.kd:data.Tfds'
cfg.train_ds.batch_size = 1
cfg.model.encoder.features = 3
cfg.workdir = os.fspath(tmp_path)

Expand Down

0 comments on commit 87f7474

Please sign in to comment.