Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import argparse
from dataclasses import dataclass
from typing import Optional

from lightning_sdk import Machine, Studio

Expand All @@ -19,8 +18,8 @@ class BenchmarkArgs:

pr_number: int
branch: str
org: Optional[str]
user: Optional[str]
org: str | None
user: str | None
teamspace: str
machine: Machine
make_args: str
Expand Down Expand Up @@ -75,7 +74,7 @@ def __init__(self, config: BenchmarkArgs):
self.org = config.org
self.machine = config.machine
self.make_args = config.make_args
self.studio: Optional[Studio] = None
self.studio: Studio | None = None

def run(self) -> None:
"""Run the LitData benchmark."""
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/litdata/optimize_imagenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import time
from functools import lru_cache, partial
from typing import Union

import numpy as np
import requests
Expand Down Expand Up @@ -126,7 +125,7 @@ def main():
seed_everything(args.seed)

# Handle resize_size: if two ints are given, treat as tuple, else int or None
resize_size: Union[int, tuple[int, int], None] = None
resize_size: int | tuple[int, int] | None = None
if args.resize_size is not None:
if isinstance(args.resize_size, list):
if len(args.resize_size) == 1:
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_modal/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import os
from typing import Any, Union
from typing import Any

import joblib
import lightning as pl
Expand Down Expand Up @@ -44,7 +44,7 @@ def load_tokenizer(self):
class DocumentClassificationDataset(StreamingDataset):
"""Streaming dataset class."""

def __init__(self, input_dir: Union[str, Any], hyperparameters: Union[dict, Any] = None) -> None:
def __init__(self, input_dir: str | Any, hyperparameters: dict | Any = None) -> None:
super().__init__(input_dir, shuffle=True, max_cache_size=hyperparameters["max_cache_size"])
self.hyperparameters = hyperparameters
self.image_transform = transforms.Compose(
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_modal/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import os
from collections.abc import Sequence
from typing import Any, Union
from typing import Any

import lightning as pl
import pandas as pd
Expand Down Expand Up @@ -259,7 +259,7 @@ def configure_optimizers(self) -> Any:
scheduler = StepLR(optimizer, step_size=1, gamma=0.1)
return [optimizer], [{"scheduler": scheduler, "interval": "epoch"}]

def configure_callbacks(self) -> Union[Sequence[pl.pytorch.Callback], pl.pytorch.Callback]:
def configure_callbacks(self) -> Sequence[pl.pytorch.Callback] | pl.pytorch.Callback:
"""Configure Early stopping or Model Checkpointing."""
early_stop = EarlyStopping(
monitor="val_MulticlassAccuracy", patience=self.hyperparameters["patience"], mode="max"
Expand Down
34 changes: 15 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ lint.extend-select = [
"SIM", # see: https://pypi.org/project/flake8-simplify
]
lint.ignore = [
"E731", # Do not assign a lambda expression, use a def
"S101", # todo: Use of `assert` detected
"UP007", # todo: non-pep604-annotation-union
"UP045", # todo: non-pep604-annotation-optional
"E731", # Do not assign a lambda expression, use a def
"S101", # todo: Use of `assert` detected
]
lint.per-file-ignores."examples/**" = [
"D100",
Expand All @@ -65,22 +63,20 @@ lint.per-file-ignores."examples/**" = [
]
lint.per-file-ignores."setup.py" = [ "D100", "SIM115" ]
lint.per-file-ignores."src/**" = [
"D100", # Missing docstring in public module
"D101", # todo: Missing docstring in public class
"D102", # todo: Missing docstring in public method
"D103", # todo: Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # todo: Missing docstring in magic method
"D107", # todo: Missing docstring in __init__
"D205", # todo: 1 blank line required between summary line and description
"D100", # Missing docstring in public module
"D101", # todo: Missing docstring in public class
"D102", # todo: Missing docstring in public method
"D103", # todo: Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # todo: Missing docstring in magic method
"D107", # todo: Missing docstring in __init__
"D205", # todo: 1 blank line required between summary line and description
"D401",
"D404", # todo: First line should be in imperative mood; try rephrasing
"S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
"S602", # todo: `subprocess` call with `shell=True` identified, security issue
"S605", # todo: Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`
"S607", # todo: Starting a process with a partial executable path
"UP006", # UP006 Use `list` instead of `List` for type annotation
"UP035", # UP035 `typing.Tuple` is deprecated, use `tuple` instead
"D404", # todo: First line should be in imperative mood; try rephrasing
"S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
"S602", # todo: `subprocess` call with `shell=True` identified, security issue
"S605", # todo: Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`
"S607", # todo: Starting a process with a partial executable path
]
lint.per-file-ignores."tests/**" = [
"D100",
Expand Down
4 changes: 2 additions & 2 deletions src/litdata/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import functools
import warnings
from typing import Any, Optional
from typing import Any

import requests
from packaging import version as packaging_version
Expand All @@ -24,7 +24,7 @@ def warn(self, message: str, stacklevel: int = 5, **kwargs: Any) -> None:


@functools.lru_cache(maxsize=1)
def _get_newer_version(curr_version: str) -> Optional[str]:
def _get_newer_version(curr_version: str) -> str | None:
"""Check PyPI for newer versions of ``litdata``.

Returning the newest version if different from the current or ``None`` otherwise.
Expand Down
4 changes: 2 additions & 2 deletions src/litdata/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import importlib
from functools import lru_cache
from importlib.util import find_spec
from typing import Optional, TypeVar
from typing import TypeVar

import pkg_resources
from typing_extensions import ParamSpec
Expand Down Expand Up @@ -83,7 +83,7 @@ class RequirementCache:

"""

def __init__(self, requirement: str, module: Optional[str] = None) -> None:
def __init__(self, requirement: str, module: str | None = None) -> None:
self.requirement = requirement
self.module = module

Expand Down
Loading
Loading