Skip to content

Commit

Permalink
Merge pull request #2593 from activeloopai/seed_docs
Browse files Browse the repository at this point in the history
Updated deeplake.random.seed documentation
  • Loading branch information
levongh committed Sep 15, 2023
2 parents 3401ae1 + 4461304 commit 28f5fb0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
35 changes: 35 additions & 0 deletions deeplake/core/seed.py
Expand Up @@ -4,13 +4,47 @@

class DeeplakeRandom(object):
def __new__(cls):
"""Returns a :class:`~deeplake.core.seed.DeeplakeRandom` object singleton instance."""
if not hasattr(cls, "instance"):
cls.instance = super(DeeplakeRandom, cls).__new__(cls)
cls.instance.internal_seed = None
cls.instance.indra_api = None
return cls.instance

def seed(self, seed: Optional[int] = None):
"""Set random seed to the deeplake engines
Args:
seed (int, optional): Integer seed for initializing the computational engines, used for bringing reproducibility to random operations.
Set to ``None`` to reset the seed. Defaults to ``None``.
Raises:
TypeError: If the provided value type is not supported.
Background
----------
Specify a seed to train models and run randomized Deep Lake operations reproducibly. Features affected are:
- Dataloader shuffling
- Sampling and random operations in Tensor Query Language (TQL)
- :meth:`Dataset.random_split <deeplake.core.dataset.Dataset.random_split>`
The random seed can be specified using ``deeplake.random.seed``:
>>> import deeplake
>>> deeplake.random.seed(0)
Random number generators in other libraries
-------------------------------------------
The Deep Lake random seed does not affect random number generators in other libraries such as ``numpy``.
However, seeds in other libraries will affect code where Deep Lake uses those libraries, but it will not impact
the methods above where Deep Lake uses its internal seed.
"""
if seed is None or isinstance(seed, int):
self.internal_seed = seed
if self.indra_api is None: # type: ignore
Expand All @@ -27,4 +61,5 @@ def seed(self, seed: Optional[int] = None):
)

def get_seed(self) -> Optional[int]:
"""Returns the seed which set to the deeplake to control the flows"""
return self.internal_seed
1 change: 1 addition & 0 deletions docs/source/Datasets.rst
Expand Up @@ -69,6 +69,7 @@ Dataset Operations
Dataset.flush
Dataset.clear_cache
Dataset.size_approx
Dataset.random_split

Dataset Visualization
~~~~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 7 additions & 0 deletions docs/source/deeplake.random.rst
@@ -0,0 +1,7 @@
deeplake.random.seed
====================

.. currentmodule:: deeplake.core.seed

.. autoclass:: DeeplakeRandom
:members:
1 change: 1 addition & 0 deletions docs/source/index.rst
Expand Up @@ -58,6 +58,7 @@ Deep Lake is an open-source database for AI.
deeplake.client.log
deeplake.core.transform
deeplake.core.vectorstore
deeplake.random


Indices and tables
Expand Down

0 comments on commit 28f5fb0

Please sign in to comment.