Skip to content

Commit

Permalink
seed docs
Browse files Browse the repository at this point in the history
  • Loading branch information
levongh committed Sep 14, 2023
1 parent 3401ae1 commit 31a1165
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions deeplake/core/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

class DeeplakeRandom(object):
def __new__(cls):
"""Returns a :class:`~deeplake.random.DeeplakeRandom` object songlton 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 to initialise the engines, used to control random behaviour and bring reproducability. Set number to initialise the engines to reset the seed set None. Defaults to None.
Raises:
TypeError: If the provided value is not expected one.
"""
if seed is None or isinstance(seed, int):
self.internal_seed = seed
if self.indra_api is None: # type: ignore
Expand All @@ -27,4 +37,6 @@ 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
46 changes: 46 additions & 0 deletions docs/source/deeplake.random.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Reproducibility
===============

Train and operate with the deeplake features and keep reproducibility between all the engines
See the ``deeplake.random.seed`` method on hot to operate with the random engines:

.. currentmodule:: deeplake.core.seed

.. autosummary::
:toctree:
:nosignatures:

deeplake.random

Deeplake random number generator
-------------------------------
Deeplake does not provide random in-house random number generator but to control the reproducibility
and keep track on the stages of
You can use :meth:`deeplake.random.seed` to seed the RNG for all the engines (both
enterprise and non enterprise)::

import deeplake
deeplake.random.seed(0)


Random number generators in other libraries
-------------------------------------------
If you or any of the libraries you are using rely on NumPy, you can seed the global
NumPy RNG with::

import numpy as np
np.random.seed(0)

import random
random.seed(0)

those will impact to all the places where deeplake uses those libraries but with use of use :meth:`deeplake.random.seed` we are nor changing any library
global state instead just initialising singlton instances in the random engines

DeeplakeRandom
~~~~~~~~~~~~~~~~~~

.. currentmodule:: deeplake.core.seed

.. autoclass:: DeeplakeRandom
:members:
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
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 31a1165

Please sign in to comment.