2022-12-13 14:47:35 +00:00
|
|
|
# Copyright The Lightning AI team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
import glob
|
Lightning Dataset (including optimized dataloading of s3 buckets) (#17743)
* Lightning DataLoader
* lightning dataloader
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* init
* example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* env var
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/__init__.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* remove unused functions
* extra reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/fileio.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports work now! yay
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* missing import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* error handling
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update creds for local use case
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* recursive get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean up get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update imagenet example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* example cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* changelog
* reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* requirements
* expose LightningDataset too
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* expost LightningDataset at top level
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove unused private methods from init
* remove private imports
* upper bound on extra requirements
* review comments
* loosen req
* deps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* test updating fabric base req
* remove version pin on s3fs to test
* recover missing function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* update
* random
* torchdata >= 0.3.0
* update torchdata version
* remove torchdata version to test
* try rem torch version pin
* req
* update bucket in test
* req
* skips
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* import
* update structure to lightning.data
* base.txt for data reqs
* fix imports
* rename to LightningS3Dataset
* new workflow
* dont need to test warnings
* reqs
* req
* revert data folder in pytorch
* test import
* tests
* req
* req
* req
* torch version
* req
* req
* open dep
* reformatted
* pin strict
* pin strict extra
* req
* modify workflow, no cache
* try
* patch
* import
* fix
* dataset test
* update getattr
* pin everything to test
* remove torch preinstall from workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* print
* skip test for now
* update path join
* revert app dep version bump
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow updates
* app base req
* req
* window test failure
* add data req to assistant
* try
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add missing comma
* updates
* update
* typo
* requirements
* try widening req
* older torch version
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* update
* update
* cleanup tests
* typo again
* update
* remove unnecessary line
* Update .github/CODEOWNERS
* Discard changes to requirements/pytorch/base.txt
* Discard changes to requirements/fabric/base.txt
* Discard changes to requirements/app/base.txt
* requirements
* requirements
* one line
* app workflow pick only app reqs
* rename package
* undo
* don't use cache
* examples CI
* pytorch and fabric CI
* try remove cache
* Apply suggestions from code review
* jirka playing
* jirka playing
* jirka playing
* blah
* flatten LightningDataset
* cleans up dataset class
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* extra
* fix dataset test
* update checkgroups
* Luca's review comments
* val error fix
* unskip test
* min
* fix precommit warning
* cpu
* docstrings
* req
* 2.0.1
* add return type
* typing errors
* req
* return types with quotations
* import for type-checking
* no botocore in cloudagnostic code
* exit args
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* backends typing
* remove oldest from data tests
* typing
* typing
* typing
* types
* type
* typing
* typing
* typing
* import fix
* Changelog
---------
Co-authored-by: Noha Alon <nohaalon@Nohas-MacBook-Air.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Co-authored-by: Jirka <jirka.borovec@seznam.cz>
Co-authored-by: Justus Schock <justus.schock@posteo.de>
2023-06-13 10:44:41 +00:00
|
|
|
import logging
|
2022-03-11 11:13:43 +00:00
|
|
|
import os
|
|
|
|
import re
|
2022-11-12 19:27:13 +00:00
|
|
|
import shutil
|
2022-12-13 14:47:35 +00:00
|
|
|
import tempfile
|
|
|
|
import urllib.request
|
2024-11-25 08:20:17 +00:00
|
|
|
from collections.abc import Iterable, Iterator, Sequence
|
2022-07-11 21:46:10 +00:00
|
|
|
from itertools import chain
|
2022-11-12 19:27:13 +00:00
|
|
|
from os.path import dirname, isfile
|
2022-07-11 21:46:10 +00:00
|
|
|
from pathlib import Path
|
2024-11-25 08:20:17 +00:00
|
|
|
from typing import Any, Optional
|
2022-03-11 11:13:43 +00:00
|
|
|
|
2024-07-15 08:54:39 +00:00
|
|
|
from packaging.requirements import Requirement
|
2024-08-04 07:28:47 +00:00
|
|
|
from packaging.version import Version
|
2022-03-11 11:13:43 +00:00
|
|
|
|
2022-07-11 21:46:10 +00:00
|
|
|
REQUIREMENT_FILES = {
|
|
|
|
"pytorch": (
|
|
|
|
"requirements/pytorch/base.txt",
|
|
|
|
"requirements/pytorch/extra.txt",
|
|
|
|
"requirements/pytorch/strategies.txt",
|
|
|
|
"requirements/pytorch/examples.txt",
|
2022-10-20 08:10:44 +00:00
|
|
|
),
|
2023-01-05 20:35:56 +00:00
|
|
|
"fabric": (
|
2023-01-04 15:57:18 +00:00
|
|
|
"requirements/fabric/base.txt",
|
|
|
|
"requirements/fabric/strategies.txt",
|
2022-10-26 18:22:46 +00:00
|
|
|
),
|
2024-02-26 13:25:00 +00:00
|
|
|
"data": ("requirements/data/data.txt",),
|
2022-07-11 21:46:10 +00:00
|
|
|
}
|
2022-10-20 14:17:27 +00:00
|
|
|
REQUIREMENT_FILES_ALL = list(chain(*REQUIREMENT_FILES.values()))
|
2022-03-11 11:13:43 +00:00
|
|
|
|
2022-12-13 14:47:35 +00:00
|
|
|
_PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
2023-01-12 16:25:29 +00:00
|
|
|
class _RequirementWithComment(Requirement):
|
|
|
|
strict_string = "# strict"
|
|
|
|
|
|
|
|
def __init__(self, *args: Any, comment: str = "", pip_argument: Optional[str] = None, **kwargs: Any) -> None:
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.comment = comment
|
|
|
|
assert pip_argument is None or pip_argument # sanity check that it's not an empty str
|
|
|
|
self.pip_argument = pip_argument
|
|
|
|
self.strict = self.strict_string in comment.lower()
|
|
|
|
|
|
|
|
def adjust(self, unfreeze: str) -> str:
|
|
|
|
"""Remove version restrictions unless they are strict.
|
|
|
|
|
|
|
|
>>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# anything").adjust("none")
|
|
|
|
'arrow<=1.2.2,>=1.2.0'
|
|
|
|
>>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# strict").adjust("none")
|
|
|
|
'arrow<=1.2.2,>=1.2.0 # strict'
|
|
|
|
>>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# my name").adjust("all")
|
|
|
|
'arrow>=1.2.0'
|
|
|
|
>>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("all")
|
|
|
|
'arrow<=1.2.2,>=1.2.0 # strict'
|
|
|
|
>>> _RequirementWithComment("arrow").adjust("all")
|
|
|
|
'arrow'
|
|
|
|
>>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# cool").adjust("major")
|
|
|
|
'arrow<2.0,>=1.2.0'
|
|
|
|
>>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("major")
|
|
|
|
'arrow<=1.2.2,>=1.2.0 # strict'
|
|
|
|
>>> _RequirementWithComment("arrow>=1.2.0").adjust("major")
|
|
|
|
'arrow>=1.2.0'
|
|
|
|
>>> _RequirementWithComment("arrow").adjust("major")
|
|
|
|
'arrow'
|
2023-08-09 14:44:20 +00:00
|
|
|
|
2023-01-12 16:25:29 +00:00
|
|
|
"""
|
|
|
|
out = str(self)
|
|
|
|
if self.strict:
|
|
|
|
return f"{out} {self.strict_string}"
|
2024-07-15 08:54:39 +00:00
|
|
|
specs = [(spec.operator, spec.version) for spec in self.specifier]
|
2023-01-12 16:25:29 +00:00
|
|
|
if unfreeze == "major":
|
2024-07-15 08:54:39 +00:00
|
|
|
for operator, version in specs:
|
2023-01-12 16:25:29 +00:00
|
|
|
if operator in ("<", "<="):
|
2024-08-04 07:28:47 +00:00
|
|
|
major = Version(version).major
|
2023-01-12 16:25:29 +00:00
|
|
|
# replace upper bound with major version increased by one
|
|
|
|
return out.replace(f"{operator}{version}", f"<{major + 1}.0")
|
|
|
|
elif unfreeze == "all":
|
2024-07-15 08:54:39 +00:00
|
|
|
for operator, version in specs:
|
2023-01-12 16:25:29 +00:00
|
|
|
if operator in ("<", "<="):
|
|
|
|
# drop upper bound
|
|
|
|
return out.replace(f"{operator}{version},", "")
|
|
|
|
elif unfreeze != "none":
|
|
|
|
raise ValueError(f"Unexpected unfreeze: {unfreeze!r} value.")
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
2024-07-15 08:54:39 +00:00
|
|
|
def _parse_requirements(lines: Iterable[str]) -> Iterator[_RequirementWithComment]:
|
2023-01-12 16:25:29 +00:00
|
|
|
"""Adapted from `pkg_resources.parse_requirements` to include comments.
|
|
|
|
|
|
|
|
>>> txt = ['# ignored', '', 'this # is an', '--piparg', 'example', 'foo # strict', 'thing', '-r different/file.txt']
|
|
|
|
>>> [r.adjust('none') for r in _parse_requirements(txt)]
|
|
|
|
['this', 'example', 'foo # strict', 'thing']
|
2023-08-09 14:44:20 +00:00
|
|
|
|
2022-12-13 14:47:35 +00:00
|
|
|
"""
|
2023-01-12 16:25:29 +00:00
|
|
|
pip_argument = None
|
|
|
|
for line in lines:
|
2024-07-15 08:54:39 +00:00
|
|
|
line = line.strip()
|
|
|
|
if not line or line.startswith("#"):
|
|
|
|
continue
|
2023-01-12 16:25:29 +00:00
|
|
|
# Drop comments -- a hash without a space may be in a URL.
|
|
|
|
if " #" in line:
|
|
|
|
comment_pos = line.find(" #")
|
|
|
|
line, comment = line[:comment_pos], line[comment_pos:]
|
|
|
|
else:
|
|
|
|
comment = ""
|
|
|
|
# If there's a pip argument, save it
|
|
|
|
if line.startswith("--"):
|
|
|
|
pip_argument = line
|
|
|
|
continue
|
|
|
|
if line.startswith("-r "):
|
|
|
|
# linked requirement files are unsupported
|
|
|
|
continue
|
|
|
|
yield _RequirementWithComment(line, comment=comment, pip_argument=pip_argument)
|
|
|
|
pip_argument = None
|
|
|
|
|
|
|
|
|
2024-11-25 08:20:17 +00:00
|
|
|
def load_requirements(path_dir: str, file_name: str = "base.txt", unfreeze: str = "all") -> list[str]:
|
2022-12-13 14:47:35 +00:00
|
|
|
"""Loading requirements from a file.
|
|
|
|
|
|
|
|
>>> path_req = os.path.join(_PROJECT_ROOT, "requirements")
|
|
|
|
>>> load_requirements(path_req, "docs.txt", unfreeze="major") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
|
2023-06-15 15:25:59 +00:00
|
|
|
['sphinx<...]
|
2023-08-09 14:44:20 +00:00
|
|
|
|
2022-12-13 14:47:35 +00:00
|
|
|
"""
|
2022-12-22 13:54:44 +00:00
|
|
|
assert unfreeze in {"none", "major", "all"}
|
2023-01-12 16:25:29 +00:00
|
|
|
path = Path(path_dir) / file_name
|
Lightning Dataset (including optimized dataloading of s3 buckets) (#17743)
* Lightning DataLoader
* lightning dataloader
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* init
* example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* env var
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/__init__.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* remove unused functions
* extra reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/fileio.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports work now! yay
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* missing import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* error handling
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update creds for local use case
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* recursive get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean up get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update imagenet example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* example cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* changelog
* reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* requirements
* expose LightningDataset too
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* expost LightningDataset at top level
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove unused private methods from init
* remove private imports
* upper bound on extra requirements
* review comments
* loosen req
* deps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* test updating fabric base req
* remove version pin on s3fs to test
* recover missing function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* update
* random
* torchdata >= 0.3.0
* update torchdata version
* remove torchdata version to test
* try rem torch version pin
* req
* update bucket in test
* req
* skips
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* import
* update structure to lightning.data
* base.txt for data reqs
* fix imports
* rename to LightningS3Dataset
* new workflow
* dont need to test warnings
* reqs
* req
* revert data folder in pytorch
* test import
* tests
* req
* req
* req
* torch version
* req
* req
* open dep
* reformatted
* pin strict
* pin strict extra
* req
* modify workflow, no cache
* try
* patch
* import
* fix
* dataset test
* update getattr
* pin everything to test
* remove torch preinstall from workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* print
* skip test for now
* update path join
* revert app dep version bump
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow updates
* app base req
* req
* window test failure
* add data req to assistant
* try
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add missing comma
* updates
* update
* typo
* requirements
* try widening req
* older torch version
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* update
* update
* cleanup tests
* typo again
* update
* remove unnecessary line
* Update .github/CODEOWNERS
* Discard changes to requirements/pytorch/base.txt
* Discard changes to requirements/fabric/base.txt
* Discard changes to requirements/app/base.txt
* requirements
* requirements
* one line
* app workflow pick only app reqs
* rename package
* undo
* don't use cache
* examples CI
* pytorch and fabric CI
* try remove cache
* Apply suggestions from code review
* jirka playing
* jirka playing
* jirka playing
* blah
* flatten LightningDataset
* cleans up dataset class
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* extra
* fix dataset test
* update checkgroups
* Luca's review comments
* val error fix
* unskip test
* min
* fix precommit warning
* cpu
* docstrings
* req
* 2.0.1
* add return type
* typing errors
* req
* return types with quotations
* import for type-checking
* no botocore in cloudagnostic code
* exit args
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* backends typing
* remove oldest from data tests
* typing
* typing
* typing
* types
* type
* typing
* typing
* typing
* import fix
* Changelog
---------
Co-authored-by: Noha Alon <nohaalon@Nohas-MacBook-Air.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Co-authored-by: Jirka <jirka.borovec@seznam.cz>
Co-authored-by: Justus Schock <justus.schock@posteo.de>
2023-06-13 10:44:41 +00:00
|
|
|
if not path.exists():
|
|
|
|
logging.warning(f"Folder {path_dir} does not have any base requirements.")
|
|
|
|
return []
|
2023-01-12 16:25:29 +00:00
|
|
|
assert path.exists(), (path_dir, file_name, path)
|
2024-07-15 08:54:39 +00:00
|
|
|
text = path.read_text().splitlines()
|
2023-01-12 16:25:29 +00:00
|
|
|
return [req.adjust(unfreeze) for req in _parse_requirements(text)]
|
2022-12-13 14:47:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def load_readme_description(path_dir: str, homepage: str, version: str) -> str:
|
|
|
|
"""Load readme as decribtion.
|
|
|
|
|
|
|
|
>>> load_readme_description(_PROJECT_ROOT, "", "") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
|
|
|
|
'...PyTorch Lightning is just organized PyTorch...'
|
2023-08-09 14:44:20 +00:00
|
|
|
|
2022-12-13 14:47:35 +00:00
|
|
|
"""
|
|
|
|
path_readme = os.path.join(path_dir, "README.md")
|
2023-04-24 21:57:08 +00:00
|
|
|
with open(path_readme, encoding="utf-8") as fo:
|
|
|
|
text = fo.read()
|
2022-12-13 14:47:35 +00:00
|
|
|
|
|
|
|
# drop images from readme
|
2023-02-28 09:04:43 +00:00
|
|
|
text = text.replace(
|
|
|
|
"![PT to PL](docs/source-pytorch/_static/images/general/pl_quick_start_full_compressed.gif)", ""
|
|
|
|
)
|
2022-12-13 14:47:35 +00:00
|
|
|
|
|
|
|
# https://github.com/Lightning-AI/lightning/raw/master/docs/source/_static/images/lightning_module/pt_to_pl.png
|
|
|
|
github_source_url = os.path.join(homepage, "raw", version)
|
|
|
|
# replace relative repository path to absolute link to the release
|
|
|
|
# do not replace all "docs" as in the readme we reger some other sources with particular path to docs
|
2023-02-28 09:04:43 +00:00
|
|
|
text = text.replace(
|
|
|
|
"docs/source-pytorch/_static/", f"{os.path.join(github_source_url, 'docs/source-app/_static/')}"
|
|
|
|
)
|
2022-12-13 14:47:35 +00:00
|
|
|
|
|
|
|
# readthedocs badge
|
|
|
|
text = text.replace("badge/?version=stable", f"badge/?version={version}")
|
|
|
|
text = text.replace("pytorch-lightning.readthedocs.io/en/stable/", f"pytorch-lightning.readthedocs.io/en/{version}")
|
|
|
|
# codecov badge
|
|
|
|
text = text.replace("/branch/master/graph/badge.svg", f"/release/{version}/graph/badge.svg")
|
|
|
|
# github actions badge
|
|
|
|
text = text.replace("badge.svg?branch=master&event=push", f"badge.svg?tag={version}")
|
|
|
|
# azure pipelines badge
|
|
|
|
text = text.replace("?branchName=master", f"?branchName=refs%2Ftags%2F{version}")
|
|
|
|
|
|
|
|
skip_begin = r"<!-- following section will be skipped from PyPI description -->"
|
|
|
|
skip_end = r"<!-- end skipping PyPI description -->"
|
|
|
|
# todo: wrap content as commented description
|
2023-08-08 14:26:06 +00:00
|
|
|
return re.sub(rf"{skip_begin}.+?{skip_end}", "<!-- -->", text, flags=re.IGNORECASE + re.DOTALL)
|
2022-12-13 14:47:35 +00:00
|
|
|
|
|
|
|
# # https://github.com/Borda/pytorch-lightning/releases/download/1.1.0a6/codecov_badge.png
|
|
|
|
# github_release_url = os.path.join(homepage, "releases", "download", version)
|
|
|
|
# # download badge and replace url with local file
|
|
|
|
# text = _parse_for_badge(text, github_release_url)
|
|
|
|
|
|
|
|
|
|
|
|
def distribute_version(src_folder: str, ver_file: str = "version.info") -> None:
|
|
|
|
"""Copy the global version to all packages."""
|
|
|
|
ls_ver = glob.glob(os.path.join(src_folder, "*", "__version__.py"))
|
|
|
|
ver_template = os.path.join(src_folder, ver_file)
|
|
|
|
for fpath in ls_ver:
|
|
|
|
fpath = os.path.join(os.path.dirname(fpath), ver_file)
|
|
|
|
print("Distributing the version to", fpath)
|
|
|
|
if os.path.isfile(fpath):
|
|
|
|
os.remove(fpath)
|
|
|
|
shutil.copy2(ver_template, fpath)
|
|
|
|
|
|
|
|
|
|
|
|
def _load_aggregate_requirements(req_dir: str = "requirements", freeze_requirements: bool = False) -> None:
|
2022-12-22 13:54:44 +00:00
|
|
|
"""Load all base requirements from all particular packages and prune duplicates.
|
|
|
|
|
|
|
|
>>> _load_aggregate_requirements(os.path.join(_PROJECT_ROOT, "requirements"))
|
2023-08-09 14:44:20 +00:00
|
|
|
|
2022-12-22 13:54:44 +00:00
|
|
|
"""
|
2022-12-13 14:47:35 +00:00
|
|
|
requires = [
|
2023-01-12 16:25:29 +00:00
|
|
|
load_requirements(d, unfreeze="none" if freeze_requirements else "major")
|
2022-12-13 14:47:35 +00:00
|
|
|
for d in glob.glob(os.path.join(req_dir, "*"))
|
Lightning Dataset (including optimized dataloading of s3 buckets) (#17743)
* Lightning DataLoader
* lightning dataloader
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* init
* example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* env var
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/__init__.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* remove unused functions
* extra reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/fileio.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports work now! yay
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* missing import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* error handling
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update creds for local use case
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* recursive get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean up get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update imagenet example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* example cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* changelog
* reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* requirements
* expose LightningDataset too
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* expost LightningDataset at top level
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove unused private methods from init
* remove private imports
* upper bound on extra requirements
* review comments
* loosen req
* deps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* test updating fabric base req
* remove version pin on s3fs to test
* recover missing function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* update
* random
* torchdata >= 0.3.0
* update torchdata version
* remove torchdata version to test
* try rem torch version pin
* req
* update bucket in test
* req
* skips
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* import
* update structure to lightning.data
* base.txt for data reqs
* fix imports
* rename to LightningS3Dataset
* new workflow
* dont need to test warnings
* reqs
* req
* revert data folder in pytorch
* test import
* tests
* req
* req
* req
* torch version
* req
* req
* open dep
* reformatted
* pin strict
* pin strict extra
* req
* modify workflow, no cache
* try
* patch
* import
* fix
* dataset test
* update getattr
* pin everything to test
* remove torch preinstall from workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* print
* skip test for now
* update path join
* revert app dep version bump
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow updates
* app base req
* req
* window test failure
* add data req to assistant
* try
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add missing comma
* updates
* update
* typo
* requirements
* try widening req
* older torch version
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* update
* update
* cleanup tests
* typo again
* update
* remove unnecessary line
* Update .github/CODEOWNERS
* Discard changes to requirements/pytorch/base.txt
* Discard changes to requirements/fabric/base.txt
* Discard changes to requirements/app/base.txt
* requirements
* requirements
* one line
* app workflow pick only app reqs
* rename package
* undo
* don't use cache
* examples CI
* pytorch and fabric CI
* try remove cache
* Apply suggestions from code review
* jirka playing
* jirka playing
* jirka playing
* blah
* flatten LightningDataset
* cleans up dataset class
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* extra
* fix dataset test
* update checkgroups
* Luca's review comments
* val error fix
* unskip test
* min
* fix precommit warning
* cpu
* docstrings
* req
* 2.0.1
* add return type
* typing errors
* req
* return types with quotations
* import for type-checking
* no botocore in cloudagnostic code
* exit args
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* backends typing
* remove oldest from data tests
* typing
* typing
* typing
* types
* type
* typing
* typing
* typing
* import fix
* Changelog
---------
Co-authored-by: Noha Alon <nohaalon@Nohas-MacBook-Air.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Co-authored-by: Jirka <jirka.borovec@seznam.cz>
Co-authored-by: Justus Schock <justus.schock@posteo.de>
2023-06-13 10:44:41 +00:00
|
|
|
# skip empty folder (git artifacts), and resolving Will's special issue
|
2023-03-24 08:46:45 +00:00
|
|
|
if os.path.isdir(d) and len(glob.glob(os.path.join(d, "*"))) > 0 and not os.path.basename(d).startswith("_")
|
2022-12-13 14:47:35 +00:00
|
|
|
]
|
|
|
|
if not requires:
|
2023-01-12 16:25:29 +00:00
|
|
|
return
|
2022-12-13 14:47:35 +00:00
|
|
|
# TODO: add some smarter version aggregation per each package
|
2022-12-22 13:54:44 +00:00
|
|
|
requires = sorted(set(chain(*requires)))
|
2022-12-13 14:47:35 +00:00
|
|
|
with open(os.path.join(req_dir, "base.txt"), "w") as fp:
|
2022-12-22 06:21:52 +00:00
|
|
|
fp.writelines([ln + os.linesep for ln in requires] + [os.linesep])
|
2022-12-13 14:47:35 +00:00
|
|
|
|
2022-07-11 21:46:10 +00:00
|
|
|
|
2024-11-25 08:20:17 +00:00
|
|
|
def _retrieve_files(directory: str, *ext: str) -> list[str]:
|
2022-10-20 14:17:27 +00:00
|
|
|
all_files = []
|
|
|
|
for root, _, files in os.walk(directory):
|
|
|
|
for fname in files:
|
|
|
|
if not ext or any(os.path.split(fname)[1].lower().endswith(e) for e in ext):
|
|
|
|
all_files.append(os.path.join(root, fname))
|
|
|
|
|
|
|
|
return all_files
|
|
|
|
|
|
|
|
|
2024-11-25 08:20:17 +00:00
|
|
|
def _replace_imports(lines: list[str], mapping: list[tuple[str, str]], lightning_by: str = "") -> list[str]:
|
2022-11-08 18:52:24 +00:00
|
|
|
"""Replace imports of standalone package to lightning.
|
|
|
|
|
|
|
|
>>> lns = [
|
2023-02-01 05:29:16 +00:00
|
|
|
... '"lightning_app"',
|
2022-11-08 18:52:24 +00:00
|
|
|
... "lightning_app",
|
2023-02-01 05:29:16 +00:00
|
|
|
... "lightning_app/",
|
2022-11-08 18:52:24 +00:00
|
|
|
... "delete_cloud_lightning_apps",
|
|
|
|
... "from lightning_app import",
|
|
|
|
... "lightning_apps = []",
|
|
|
|
... "lightning_app and pytorch_lightning are ours",
|
|
|
|
... "def _lightning_app():",
|
2023-02-01 05:29:16 +00:00
|
|
|
... ":class:`~lightning_app.core.flow.LightningFlow`",
|
2023-02-01 11:07:00 +00:00
|
|
|
... "http://pytorch_lightning.ai",
|
2023-02-01 05:29:16 +00:00
|
|
|
... "from lightning import __version__",
|
|
|
|
... "@lightning.ai"
|
2022-11-08 18:52:24 +00:00
|
|
|
... ]
|
|
|
|
>>> mapping = [("lightning_app", "lightning.app"), ("pytorch_lightning", "lightning.pytorch")]
|
2023-02-01 05:29:16 +00:00
|
|
|
>>> _replace_imports(lns, mapping, lightning_by="lightning_fabric") # doctest: +NORMALIZE_WHITESPACE
|
2023-02-01 11:07:00 +00:00
|
|
|
['"lightning.app"', \
|
|
|
|
'lightning.app', \
|
|
|
|
'lightning_app/', \
|
|
|
|
'delete_cloud_lightning_apps', \
|
|
|
|
'from lightning.app import', \
|
|
|
|
'lightning_apps = []', \
|
|
|
|
'lightning.app and lightning.pytorch are ours', \
|
|
|
|
'def _lightning_app():', \
|
|
|
|
':class:`~lightning.app.core.flow.LightningFlow`', \
|
|
|
|
'http://pytorch_lightning.ai', \
|
|
|
|
'from lightning_fabric import __version__', \
|
|
|
|
'@lightning.ai']
|
2023-08-09 14:44:20 +00:00
|
|
|
|
2022-11-08 18:52:24 +00:00
|
|
|
"""
|
|
|
|
out = lines[:]
|
|
|
|
for source_import, target_import in mapping:
|
|
|
|
for i, ln in enumerate(out):
|
2023-02-01 05:29:16 +00:00
|
|
|
out[i] = re.sub(
|
|
|
|
rf"([^_/@]|^){source_import}([^_\w/]|$)",
|
|
|
|
rf"\1{target_import}\2",
|
|
|
|
ln,
|
|
|
|
)
|
|
|
|
if lightning_by: # in addition, replace base package
|
|
|
|
out[i] = out[i].replace("from lightning import ", f"from {lightning_by} import ")
|
|
|
|
out[i] = out[i].replace("import lightning ", f"import {lightning_by} ")
|
2022-11-08 18:52:24 +00:00
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
def copy_replace_imports(
|
2023-02-01 05:29:16 +00:00
|
|
|
source_dir: str,
|
|
|
|
source_imports: Sequence[str],
|
|
|
|
target_imports: Sequence[str],
|
|
|
|
target_dir: Optional[str] = None,
|
|
|
|
lightning_by: str = "",
|
2022-11-08 18:52:24 +00:00
|
|
|
) -> None:
|
2022-11-12 19:27:13 +00:00
|
|
|
"""Copy package content with import adjustments."""
|
2022-11-08 18:52:24 +00:00
|
|
|
print(f"Replacing imports: {locals()}")
|
|
|
|
assert len(source_imports) == len(target_imports), (
|
|
|
|
"source and target imports must have the same length, "
|
|
|
|
f"source: {len(source_imports)}, target: {len(target_imports)}"
|
|
|
|
)
|
|
|
|
if target_dir is None:
|
|
|
|
target_dir = source_dir
|
|
|
|
|
|
|
|
ls = _retrieve_files(source_dir)
|
|
|
|
for fp in ls:
|
2022-11-12 19:27:13 +00:00
|
|
|
fp_new = fp.replace(source_dir, target_dir)
|
|
|
|
_, ext = os.path.splitext(fp)
|
|
|
|
if ext in (".png", ".jpg", ".ico"):
|
|
|
|
os.makedirs(dirname(fp_new), exist_ok=True)
|
|
|
|
if not isfile(fp_new):
|
|
|
|
shutil.copy(fp, fp_new)
|
|
|
|
continue
|
2023-05-05 09:34:40 +00:00
|
|
|
if ext in (".pyc",):
|
2022-11-12 19:27:13 +00:00
|
|
|
continue
|
|
|
|
# Try to parse everything else
|
|
|
|
with open(fp, encoding="utf-8") as fo:
|
|
|
|
try:
|
|
|
|
lines = fo.readlines()
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
# a binary file, skip
|
|
|
|
print(f"Skipped replacing imports for {fp}")
|
|
|
|
continue
|
2023-02-01 05:29:16 +00:00
|
|
|
lines = _replace_imports(lines, list(zip(source_imports, target_imports)), lightning_by=lightning_by)
|
2022-11-12 19:27:13 +00:00
|
|
|
os.makedirs(os.path.dirname(fp_new), exist_ok=True)
|
|
|
|
with open(fp_new, "w", encoding="utf-8") as fo:
|
|
|
|
fo.writelines(lines)
|
2022-11-08 18:52:24 +00:00
|
|
|
|
|
|
|
|
2024-11-25 08:20:17 +00:00
|
|
|
def create_mirror_package(source_dir: str, package_mapping: dict[str, str]) -> None:
|
2024-03-19 15:35:40 +00:00
|
|
|
"""Create a mirror package with adjusted imports."""
|
2022-11-08 18:52:24 +00:00
|
|
|
# replace imports and copy the code
|
|
|
|
mapping = package_mapping.copy()
|
|
|
|
mapping.pop("lightning", None) # pop this key to avoid replacing `lightning` to `lightning.lightning`
|
2023-02-01 05:29:16 +00:00
|
|
|
|
|
|
|
mapping = {f"lightning.{sp}": sl for sp, sl in mapping.items()}
|
2023-02-02 14:10:29 +00:00
|
|
|
for pkg_from, pkg_to in mapping.items():
|
2024-03-19 15:35:40 +00:00
|
|
|
source_imports, target_imports = zip(*mapping.items())
|
2022-11-08 18:52:24 +00:00
|
|
|
copy_replace_imports(
|
2023-02-01 05:29:16 +00:00
|
|
|
source_dir=os.path.join(source_dir, pkg_from.replace(".", os.sep)),
|
2023-01-04 15:57:18 +00:00
|
|
|
# pytorch_lightning uses lightning_fabric, so we need to replace all imports for all directories
|
2024-03-19 15:35:40 +00:00
|
|
|
source_imports=source_imports,
|
|
|
|
target_imports=target_imports,
|
2023-02-01 05:29:16 +00:00
|
|
|
target_dir=os.path.join(source_dir, pkg_to.replace(".", os.sep)),
|
2023-02-02 14:10:29 +00:00
|
|
|
lightning_by=pkg_from,
|
2022-11-08 18:52:24 +00:00
|
|
|
)
|
2022-03-11 11:13:43 +00:00
|
|
|
|
|
|
|
|
2022-11-08 18:52:24 +00:00
|
|
|
class AssistantCLI:
|
2022-03-11 11:13:43 +00:00
|
|
|
@staticmethod
|
2022-07-11 21:46:10 +00:00
|
|
|
def requirements_prune_pkgs(packages: Sequence[str], req_files: Sequence[str] = REQUIREMENT_FILES_ALL) -> None:
|
2022-03-21 12:50:50 +00:00
|
|
|
"""Remove some packages from given requirement files."""
|
|
|
|
if isinstance(req_files, str):
|
|
|
|
req_files = [req_files]
|
|
|
|
for req in req_files:
|
|
|
|
AssistantCLI._prune_packages(req, packages)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _prune_packages(req_file: str, packages: Sequence[str]) -> None:
|
2022-03-11 11:13:43 +00:00
|
|
|
"""Remove some packages from given requirement files."""
|
2022-07-15 17:41:23 +00:00
|
|
|
path = Path(req_file)
|
|
|
|
assert path.exists()
|
|
|
|
text = path.read_text()
|
2022-10-20 14:17:27 +00:00
|
|
|
lines = text.splitlines()
|
|
|
|
final = []
|
|
|
|
for line in lines:
|
|
|
|
ln_ = line.strip()
|
|
|
|
if not ln_ or ln_.startswith("#"):
|
|
|
|
final.append(line)
|
|
|
|
continue
|
2024-07-15 08:54:39 +00:00
|
|
|
req = list(_parse_requirements([ln_]))[0]
|
2022-10-20 14:17:27 +00:00
|
|
|
if req.name not in packages:
|
|
|
|
final.append(line)
|
2022-11-12 19:27:13 +00:00
|
|
|
print(final)
|
2022-12-22 06:21:52 +00:00
|
|
|
path.write_text("\n".join(final) + "\n")
|
2022-03-11 11:13:43 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _replace_min(fname: str) -> None:
|
2023-04-24 21:57:08 +00:00
|
|
|
with open(fname, encoding="utf-8") as fo:
|
|
|
|
req = fo.read().replace(">=", "==")
|
|
|
|
with open(fname, "w", encoding="utf-8") as fw:
|
|
|
|
fw.write(req)
|
2022-03-11 11:13:43 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-07-11 21:46:10 +00:00
|
|
|
def replace_oldest_ver(requirement_fnames: Sequence[str] = REQUIREMENT_FILES_ALL) -> None:
|
2022-03-11 11:13:43 +00:00
|
|
|
"""Replace the min package version by fixed one."""
|
|
|
|
for fname in requirement_fnames:
|
Lightning Dataset (including optimized dataloading of s3 buckets) (#17743)
* Lightning DataLoader
* lightning dataloader
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* init
* example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* env var
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/__init__.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* remove unused functions
* extra reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update src/lightning/pytorch/utilities/data/fileio.py
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports work now! yay
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* imports
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* missing import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* error handling
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update creds for local use case
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* recursive get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean up get index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update imagenet example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* docstrings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* example cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* changelog
* reqs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codeowners
* requirements
* expose LightningDataset too
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* expost LightningDataset at top level
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove unused private methods from init
* remove private imports
* upper bound on extra requirements
* review comments
* loosen req
* deps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* test updating fabric base req
* remove version pin on s3fs to test
* recover missing function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* tests
* update
* random
* torchdata >= 0.3.0
* update torchdata version
* remove torchdata version to test
* try rem torch version pin
* req
* update bucket in test
* req
* skips
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* import
* update structure to lightning.data
* base.txt for data reqs
* fix imports
* rename to LightningS3Dataset
* new workflow
* dont need to test warnings
* reqs
* req
* revert data folder in pytorch
* test import
* tests
* req
* req
* req
* torch version
* req
* req
* open dep
* reformatted
* pin strict
* pin strict extra
* req
* modify workflow, no cache
* try
* patch
* import
* fix
* dataset test
* update getattr
* pin everything to test
* remove torch preinstall from workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* workflow
* req
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow
* print
* skip test for now
* update path join
* revert app dep version bump
* Update .github/workflows/ci-tests-data.yml
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
* workflow updates
* app base req
* req
* window test failure
* add data req to assistant
* try
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add missing comma
* updates
* update
* typo
* requirements
* try widening req
* older torch version
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* update
* update
* cleanup tests
* typo again
* update
* remove unnecessary line
* Update .github/CODEOWNERS
* Discard changes to requirements/pytorch/base.txt
* Discard changes to requirements/fabric/base.txt
* Discard changes to requirements/app/base.txt
* requirements
* requirements
* one line
* app workflow pick only app reqs
* rename package
* undo
* don't use cache
* examples CI
* pytorch and fabric CI
* try remove cache
* Apply suggestions from code review
* jirka playing
* jirka playing
* jirka playing
* blah
* flatten LightningDataset
* cleans up dataset class
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* jirka playing
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* extra
* fix dataset test
* update checkgroups
* Luca's review comments
* val error fix
* unskip test
* min
* fix precommit warning
* cpu
* docstrings
* req
* 2.0.1
* add return type
* typing errors
* req
* return types with quotations
* import for type-checking
* no botocore in cloudagnostic code
* exit args
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* backends typing
* remove oldest from data tests
* typing
* typing
* typing
* types
* type
* typing
* typing
* typing
* import fix
* Changelog
---------
Co-authored-by: Noha Alon <nohaalon@Nohas-MacBook-Air.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Co-authored-by: Jirka <jirka.borovec@seznam.cz>
Co-authored-by: Justus Schock <justus.schock@posteo.de>
2023-06-13 10:44:41 +00:00
|
|
|
print(fname)
|
2022-03-11 11:13:43 +00:00
|
|
|
AssistantCLI._replace_min(fname)
|
|
|
|
|
2022-10-20 14:17:27 +00:00
|
|
|
@staticmethod
|
|
|
|
def copy_replace_imports(
|
2023-02-01 05:29:16 +00:00
|
|
|
source_dir: str,
|
|
|
|
source_import: str,
|
|
|
|
target_import: str,
|
|
|
|
target_dir: Optional[str] = None,
|
|
|
|
lightning_by: str = "",
|
2022-10-20 14:17:27 +00:00
|
|
|
) -> None:
|
2022-11-12 19:27:13 +00:00
|
|
|
"""Copy package content with import adjustments."""
|
2022-10-20 14:17:27 +00:00
|
|
|
source_imports = source_import.strip().split(",")
|
|
|
|
target_imports = target_import.strip().split(",")
|
2023-02-01 05:29:16 +00:00
|
|
|
copy_replace_imports(
|
|
|
|
source_dir, source_imports, target_imports, target_dir=target_dir, lightning_by=lightning_by
|
|
|
|
)
|
2022-10-20 14:17:27 +00:00
|
|
|
|
2023-06-21 15:32:20 +00:00
|
|
|
@staticmethod
|
|
|
|
def pull_docs_files(
|
|
|
|
gh_user_repo: str,
|
|
|
|
target_dir: str = "docs/source-pytorch/XXX",
|
2023-11-02 16:45:00 +00:00
|
|
|
checkout: str = "refs/tags/1.0.0",
|
2023-06-21 15:32:20 +00:00
|
|
|
source_dir: str = "docs/source",
|
2024-01-09 12:12:53 +00:00
|
|
|
single_page: Optional[str] = None,
|
2023-10-03 19:02:47 +00:00
|
|
|
as_orphan: bool = False,
|
2023-06-21 15:32:20 +00:00
|
|
|
) -> None:
|
2024-01-09 12:12:53 +00:00
|
|
|
"""Pull docs pages from external source and append to local docs.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
gh_user_repo: standard GitHub user/repo string
|
|
|
|
target_dir: relative location inside the docs folder
|
|
|
|
checkout: specific tag or branch to checkout
|
|
|
|
source_dir: relative location inside the remote / external repo
|
|
|
|
single_page: copy only single page from the remote repo and name it as the repo name
|
|
|
|
as_orphan: append orphan statement to the page
|
|
|
|
|
|
|
|
"""
|
2023-06-21 15:32:20 +00:00
|
|
|
import zipfile
|
|
|
|
|
2023-11-02 16:45:00 +00:00
|
|
|
zip_url = f"https://github.com/{gh_user_repo}/archive/{checkout}.zip"
|
2023-06-21 15:32:20 +00:00
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
|
|
zip_file = os.path.join(tmp, "repo.zip")
|
2023-09-21 10:36:15 +00:00
|
|
|
try:
|
|
|
|
urllib.request.urlretrieve(zip_url, zip_file)
|
|
|
|
except urllib.error.HTTPError:
|
2023-09-28 19:26:06 +00:00
|
|
|
raise RuntimeError(f"Requesting file '{zip_url}' does not exist or it is just unavailable.")
|
2023-06-21 15:32:20 +00:00
|
|
|
|
|
|
|
with zipfile.ZipFile(zip_file, "r") as zip_ref:
|
2024-07-05 11:56:29 +00:00
|
|
|
zip_ref.extractall(tmp)
|
2023-06-21 15:32:20 +00:00
|
|
|
|
|
|
|
zip_dirs = [d for d in glob.glob(os.path.join(tmp, "*")) if os.path.isdir(d)]
|
|
|
|
# check that the extracted archive has only repo folder
|
|
|
|
assert len(zip_dirs) == 1
|
|
|
|
repo_dir = zip_dirs[0]
|
|
|
|
|
2024-01-09 12:12:53 +00:00
|
|
|
if single_page: # special case for copying single page
|
|
|
|
single_page = os.path.join(repo_dir, source_dir, single_page)
|
|
|
|
assert os.path.isfile(single_page), f"File '{single_page}' does not exist."
|
|
|
|
name = re.sub(r"lightning[-_]?", "", gh_user_repo.split("/")[-1])
|
|
|
|
new_rst = os.path.join(_PROJECT_ROOT, target_dir, f"{name}.rst")
|
|
|
|
AssistantCLI._copy_rst(single_page, new_rst, as_orphan=as_orphan)
|
|
|
|
return
|
|
|
|
# continue with copying all pages
|
2023-06-21 15:32:20 +00:00
|
|
|
ls_pages = glob.glob(os.path.join(repo_dir, source_dir, "*.rst"))
|
|
|
|
ls_pages += glob.glob(os.path.join(repo_dir, source_dir, "**", "*.rst"))
|
|
|
|
for rst in ls_pages:
|
|
|
|
rel_rst = rst.replace(os.path.join(repo_dir, source_dir) + os.path.sep, "")
|
|
|
|
rel_dir = os.path.dirname(rel_rst)
|
|
|
|
os.makedirs(os.path.join(_PROJECT_ROOT, target_dir, rel_dir), exist_ok=True)
|
|
|
|
new_rst = os.path.join(_PROJECT_ROOT, target_dir, rel_rst)
|
|
|
|
if os.path.isfile(new_rst):
|
|
|
|
logging.warning(f"Page {new_rst} already exists in the local tree so it will be skipped.")
|
|
|
|
continue
|
2023-10-03 19:02:47 +00:00
|
|
|
AssistantCLI._copy_rst(rst, new_rst, as_orphan=as_orphan)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _copy_rst(rst_in, rst_out, as_orphan: bool = False):
|
|
|
|
"""Copy RST page with optional inserting orphan statement."""
|
|
|
|
with open(rst_in, encoding="utf-8") as fopen:
|
|
|
|
page = fopen.read()
|
|
|
|
if as_orphan and ":orphan:" not in page:
|
|
|
|
page = ":orphan:\n\n" + page
|
2023-11-02 16:45:00 +00:00
|
|
|
with open(rst_out, "w", encoding="utf-8") as fopen:
|
2023-10-03 19:02:47 +00:00
|
|
|
fopen.write(page)
|
2023-06-21 15:32:20 +00:00
|
|
|
|
2024-03-17 12:49:35 +00:00
|
|
|
@staticmethod
|
|
|
|
def convert_version2nightly(ver_file: str = "src/version.info") -> None:
|
|
|
|
"""Load the actual version and convert it to the nightly version."""
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
with open(ver_file) as fo:
|
|
|
|
version = fo.read().strip()
|
|
|
|
# parse X.Y.Z version and prune any suffix
|
|
|
|
vers = re.match(r"(\d+)\.(\d+)\.(\d+).*", version)
|
|
|
|
# create timestamp YYYYMMDD
|
|
|
|
timestamp = datetime.now().strftime("%Y%m%d")
|
|
|
|
version = f"{'.'.join(vers.groups())}.dev{timestamp}"
|
|
|
|
with open(ver_file, "w") as fo:
|
|
|
|
fo.write(version + os.linesep)
|
|
|
|
|
2024-12-20 09:05:50 +00:00
|
|
|
@staticmethod
|
|
|
|
def generate_docker_tags(
|
|
|
|
release_version: str,
|
|
|
|
python_version: str,
|
|
|
|
torch_version: str,
|
|
|
|
cuda_version: str,
|
|
|
|
docker_project: str = "pytorchlightning/pytorch_lightning",
|
|
|
|
add_latest: bool = False,
|
|
|
|
) -> None:
|
|
|
|
"""Generate docker tags for the given versions."""
|
|
|
|
tags = [f"latest-py{python_version}-torch{torch_version}-cuda{cuda_version}"]
|
|
|
|
if release_version:
|
|
|
|
tags += [f"{release_version}-py{python_version}-torch{torch_version}-cuda{cuda_version}"]
|
|
|
|
if add_latest:
|
|
|
|
tags += ["latest"]
|
|
|
|
|
|
|
|
tags = [f"{docker_project}:{tag}" for tag in tags]
|
|
|
|
print(",".join(tags))
|
|
|
|
|
2022-03-11 11:13:43 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-11-08 18:52:24 +00:00
|
|
|
import jsonargparse
|
|
|
|
|
2022-10-20 18:23:47 +00:00
|
|
|
jsonargparse.CLI(AssistantCLI, as_positional=False)
|