Commit d2636b4e authored by Jonathan Tow's avatar Jonathan Tow
Browse files

Enforce `rnd` args with assertions

parent 0e232f7a
...@@ -471,13 +471,13 @@ class Task(abc.ABC): ...@@ -471,13 +471,13 @@ class Task(abc.ABC):
Not implemented, and this option is deprecated and will be removed in a future version in favor of a different description providing method Not implemented, and this option is deprecated and will be removed in a future version in favor of a different description providing method
:param rnd: random.Random :param rnd: random.Random
The pseudo-random number generator used to randomly sample examples. The pseudo-random number generator used to randomly sample examples.
WARNING: If you do not provide a `rnd` arg, a default `random.Random` WARNING: This is currently a required arg although it's optionalized with a default `None`.
object will be created and seeded with this Task's name attribute, `__name__`.
:param description: str :param description: str
The task's description that will be prepended to the fewshot examples. The task's description that will be prepended to the fewshot examples.
:returns: str :returns: str
The fewshot context. The fewshot context.
""" """
assert rnd is not None, "A `random.Random` generator argument must be provided to `rnd`"
assert not provide_description, ( assert not provide_description, (
"The `provide_description` arg will be removed in future versions. To prepend " "The `provide_description` arg will be removed in future versions. To prepend "
"a custom description to the context, supply the corresponding string via the " "a custom description to the context, supply the corresponding string via the "
...@@ -489,11 +489,6 @@ class Task(abc.ABC): ...@@ -489,11 +489,6 @@ class Task(abc.ABC):
description = description + "\n\n" if description else "" description = description + "\n\n" if description else ""
# TODO (jon-tow): Remove this default `rand` behaviour after `provide_description` is removed and remove the respective `rand` arg warning in the docs above.
if rnd is None:
rnd = random.Random()
rnd.seed(self.__name__)
if num_fewshot == 0: if num_fewshot == 0:
labeled_examples = "" labeled_examples = ""
else: else:
...@@ -567,6 +562,7 @@ class PerplexityTask(Task, abc.ABC): ...@@ -567,6 +562,7 @@ class PerplexityTask(Task, abc.ABC):
def fewshot_context(self, doc, num_fewshot, provide_description=None, rnd=None, description=None): def fewshot_context(self, doc, num_fewshot, provide_description=None, rnd=None, description=None):
assert num_fewshot == 0 assert num_fewshot == 0
assert rnd is not None, "A `random.Random` generator argument must be provided to `rnd`"
assert not provide_description, ( assert not provide_description, (
"The `provide_description` arg will be removed in future versions. To prepend " "The `provide_description` arg will be removed in future versions. To prepend "
"a custom description to the context, supply the corresponding string via the " "a custom description to the context, supply the corresponding string via the "
...@@ -576,11 +572,6 @@ class PerplexityTask(Task, abc.ABC): ...@@ -576,11 +572,6 @@ class PerplexityTask(Task, abc.ABC):
# nudge people to not specify it at all # nudge people to not specify it at all
print("WARNING: provide_description is deprecated and will be removed in a future version in favor of description_dict") print("WARNING: provide_description is deprecated and will be removed in a future version in favor of description_dict")
# TODO (jon-tow): Remove this default `rand` behaviour after `provide_description` is removed and remove the respective `rand` arg warning in the docs above.
if rnd is None:
rnd = random.Random()
rnd.seed(self.__name__)
return "" return ""
def higher_is_better(self): def higher_is_better(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment