-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Progress Bar, Backoff, Batching #165
Open
soldni
wants to merge
16
commits into
main
Choose a base branch
from
soldni/pbar2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
35719fc
added support for old-style retries_on_error
soldni 67b3bda
added support for retries_on_error
soldni 155319c
data
soldni d8cb681
deps
soldni e6270dc
get_annotations not available
soldni 75a5b0d
fixes
soldni 86371d6
quoting type aliases
soldni 73aad08
3.8 compatibility
soldni b9ec3eb
more style
soldni e42f9fc
pyi
soldni be6c984
viz pbar
soldni f5c696c
fixing small regression in tests
soldni e941f05
order from user
soldni 1e292ff
min timeout
soldni d805ee3
Merge branch 'main' into soldni/pbar2
soldni 3d5baab
Merge branch 'main' into soldni/pbar2
soldni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ dependencies = [ | |
"omegaconf>=2.3.0", | ||
# "pycld2==0.41", | ||
# "pycld3==0.22", # does not install correctly | ||
"hyperscan>=0.7.0", | ||
"platformdirs>=4.2.0", | ||
"pyyaml", | ||
"requests", | ||
|
@@ -30,6 +31,8 @@ dependencies = [ | |
"numpy", | ||
"necessary>=0.4.3", | ||
"charset-normalizer>=3.2.0", | ||
"zstandard>=0.20.0", | ||
"backoff>=2.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this version required? There's 2 minor versions since this 2.0 release "2.2.1" |
||
] | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
|
@@ -99,7 +102,7 @@ dolma = "dolma.cli.__main__:main" | |
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"black>=22.6.0", | ||
"black[jupyter]>=22.6.0", | ||
"flake8>=5.0", | ||
"flake8-pyi>=22.8.1", | ||
"Flake8-pyproject>=1.1.0", | ||
|
@@ -127,7 +130,6 @@ warc = [ | |
"fastwarc", | ||
"w3lib", | ||
"url-normalize", | ||
|
||
] | ||
trafilatura = [ | ||
# must include warc dependencies | ||
|
@@ -159,7 +161,7 @@ all = [ | |
|
||
[build-system] | ||
requires = [ | ||
"maturin[patchelf]>=1.1,<2.0", | ||
"maturin>=1.5,<2.0", | ||
"setuptools >= 61.0.0", | ||
"wheel" | ||
] | ||
|
@@ -175,7 +177,7 @@ features = ["pyo3/extension-module"] | |
where = ["src"] | ||
|
||
[tool.setuptools.package-data] | ||
dolma = ["py.typed", "data/*"] | ||
dolma = ["py.typed", "data/*", "*.pyi"] | ||
|
||
[tool.black] | ||
line-length = 115 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import multiprocessing | ||
import time | ||
from contextlib import ExitStack | ||
from multiprocessing.managers import SyncManager | ||
from multiprocessing.pool import Pool | ||
from queue import Queue | ||
from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union | ||
|
||
T = TypeVar("T") | ||
R = TypeVar("R") | ||
|
||
|
||
def get_manager(pool: Union[Pool, "PoolWithDebug"]) -> Union[SyncManager, "ManagerWithDebug"]: | ||
if getattr(pool, "debug", False): | ||
return ManagerWithDebug() | ||
else: | ||
return multiprocessing.Manager() | ||
|
||
|
||
class ResultWithDebug(Generic[T]): | ||
def __init__(self, result: T, *args, **kwargs): | ||
self.result = result | ||
|
||
def get(self, timeout: Optional[float] = None) -> T: | ||
return self.result | ||
|
||
def wait(self, timeout: Optional[float] = None) -> None: | ||
time.sleep(timeout or 0) | ||
|
||
def successful(self) -> bool: | ||
return True | ||
|
||
def ready(self) -> bool: | ||
return True | ||
|
||
|
||
class ManagerWithDebug: | ||
def Queue(self): | ||
return Queue() | ||
|
||
def shutdown(self) -> None: | ||
pass | ||
|
||
|
||
class PoolWithDebug: | ||
"""A wrapper around multiprocessing.Pool that allows for debugging (i.e., running without multiprocessing). | ||
Supports creating a manager for shared memory objects (mock in case of debugging).""" | ||
|
||
def __init__( | ||
self, | ||
processes: Optional[int] = None, | ||
initializer: Optional[Callable[..., Any]] = None, | ||
initargs: Iterable[Any] = (), | ||
maxtasksperchild: Optional[int] = None, | ||
debug: bool = False, | ||
): | ||
self.processes = processes | ||
self.initializer = initializer | ||
self.initargs = initargs | ||
self.maxtasksperchild = maxtasksperchild | ||
self.debug = debug | ||
|
||
# we are gonna keep track of resources in stack; but also keeping them indexed | ||
# separately for easy access | ||
self.stack = ExitStack() | ||
self._manager: Optional[SyncManager] = None | ||
self._pool: Optional[Pool] = None | ||
|
||
# let's make sure that the start method is spawn for best performance | ||
try: | ||
multiprocessing.set_start_method("spawn") | ||
except RuntimeError: | ||
assert multiprocessing.get_start_method() == "spawn", "Multiprocessing start method must be spawn" | ||
|
||
def __enter__(self): | ||
if self._pool is None and not self.debug: | ||
self._pool = self.stack.enter_context( | ||
Pool( | ||
processes=self.processes, | ||
initializer=self.initializer, | ||
initargs=self.initargs, | ||
maxtasksperchild=self.maxtasksperchild, | ||
) | ||
) | ||
return self | ||
|
||
def Manager(self): | ||
if self._manager is None: | ||
self._manager = ( | ||
ManagerWithDebug() # pyright: ignore | ||
if self.debug | ||
else self.stack.enter_context(multiprocessing.Manager()) | ||
) | ||
return self._manager | ||
|
||
def __exit__(self, *exc): | ||
return self.stack.close() | ||
|
||
def apply_async( | ||
self, | ||
func: Callable[..., R], | ||
args: Iterable[Any] = (), | ||
kwds: Dict[str, Any] = {}, | ||
callback: Optional[Callable[[R], Any]] = None, | ||
error_callback: Optional[Callable[[Any], Any]] = None, | ||
): | ||
if self._pool is None: | ||
if self.initializer: | ||
# run the initializer once by calling it with the initargs and then setting it to None | ||
self.initializer(*self.initargs) | ||
self.initializer = None | ||
try: | ||
resp = func(*args, **kwds) | ||
if callback is not None: | ||
callback(resp) | ||
return ResultWithDebug(resp) | ||
except Exception as e: | ||
if error_callback is not None: | ||
error_callback(e) | ||
raise e | ||
else: | ||
return self._pool.apply_async( | ||
func=func, args=args, kwds=kwds, callback=callback, error_callback=error_callback | ||
) | ||
|
||
def close(self): | ||
return self._pool and self._pool.close() | ||
|
||
def join(self): | ||
return self._pool and self._pool.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from collections.abc import Callable, Iterable | ||
from multiprocessing.managers import SyncManager | ||
from multiprocessing.pool import ApplyResult, Pool | ||
from typing import Any | ||
|
||
class ResultWithDebug(ApplyResult): ... # noqa: E701,E302 | ||
class ManagerWithDebug(SyncManager): ... # noqa: E701 | ||
|
||
class PoolWithDebug(Pool): # noqa: E302 | ||
def __init__( # noqa: E704 | ||
self, | ||
processes: int | None = None, | ||
initializer: Callable[..., Any] | None = None, | ||
initargs: Iterable[Any] = (), | ||
maxtasksperchild: int | None = None, | ||
debug: bool = False, | ||
): ... | ||
|
||
def get_manager(pool: Pool) -> SyncManager: ... # noqa: E701, E704, E302 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏