Skip to content

Commit

Permalink
Cleanup dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
blythed committed Jan 16, 2025
1 parent c26aebd commit 74381a7
Show file tree
Hide file tree
Showing 84 changed files with 122 additions and 1,406 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# superduper.io Changelog

All notable changes to this project will be documented in this file.
All notable changes to this project will be documented in this file

The format is inspired by (but not strictly follows) [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Expand Down
2 changes: 1 addition & 1 deletion plugins/anthropic/superduper_anthropic/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from anthropic import APIConnectionError, APIError, APIStatusError, APITimeoutError
from superduper.backends.query_dataset import QueryDataset
from superduper.components.model import APIBaseModel
from superduper.ext.utils import format_prompt, get_key
from superduper.misc.retry import Retry
from superduper.misc.utils import format_prompt, get_key

retry = Retry(
exception_types=(APIConnectionError, APIError, APIStatusError, APITimeoutError)
Expand Down
2 changes: 1 addition & 1 deletion plugins/cohere/superduper_cohere/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from cohere.error import CohereAPIError, CohereConnectionError
from superduper.backends.query_dataset import QueryDataset
from superduper.components.model import APIBaseModel
from superduper.ext.utils import format_prompt, get_key
from superduper.misc.retry import Retry
from superduper.misc.utils import format_prompt, get_key

retry = Retry(exception_types=(CohereAPIError, CohereConnectionError))

Expand Down
2 changes: 1 addition & 1 deletion plugins/ibis/superduper_ibis/data_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, uri: str, flavour: t.Optional[str] = None):
self.overwrite = False
self._setup(conn)

self.datatype_presets = {'vector': 'superduper.ext.numpy.encoder.Array'}
self.datatype_presets = {'vector': 'superduper.components.datatype.Array'}

if uri.startswith('snowflake://'):
self.bytes_encoding = 'base64'
Expand Down
2 changes: 1 addition & 1 deletion plugins/jina/superduper_jina/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import requests
from aiohttp import ClientConnectionError, ClientResponseError
from requests.exceptions import HTTPError
from superduper.ext.utils import get_key
from superduper.misc.retry import Retry
from superduper.misc.utils import get_key

JINA_API_URL: str = "https://api.jina.ai/v1/embeddings"
KEY_NAME = 'JINA_API_KEY'
Expand Down
2 changes: 1 addition & 1 deletion plugins/mongodb/plugin_test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np
import pytest
from superduper.base.document import Document
from superduper.components.datatype import Array
from superduper.components.schema import Schema
from superduper.components.table import Table
from superduper.ext.numpy.encoder import Array

from superduper_mongodb.query import MongoQuery

Expand Down
5 changes: 2 additions & 3 deletions plugins/mongodb/superduper_mongodb/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import gridfs
from superduper import CFG, logging
from superduper.backends.base.artifacts import ArtifactStore
from superduper.misc.colors import Colors
from tqdm import tqdm

from superduper_mongodb.utils import connection_callback
Expand Down Expand Up @@ -48,8 +47,8 @@ def drop(self, force: bool = False):
"""
if not force:
if not click.confirm(
f'{Colors.RED}[!!!WARNING USE WITH CAUTION AS YOU '
f'WILL LOSE ALL DATA!!!]{Colors.RESET} '
'!!!WARNING USE WITH CAUTION AS YOU '
'WILL LOSE ALL DATA!!!]\n'
'Are you sure you want to drop all artifacts? ',
default=False,
):
Expand Down
5 changes: 2 additions & 3 deletions plugins/mongodb/superduper_mongodb/data_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from superduper.base.enums import DBType
from superduper.components.datatype import BaseDataType
from superduper.components.schema import Schema
from superduper.misc.colors import Colors

from superduper_mongodb.artifacts import MongoArtifactStore
from superduper_mongodb.metadata import MongoMetaDataStore
Expand Down Expand Up @@ -113,8 +112,8 @@ def drop(self, force: bool = False):
"""
if not force:
if not click.confirm(
f"{Colors.RED}[!!!WARNING USE WITH CAUTION AS YOU "
f"WILL LOSE ALL DATA!!!]{Colors.RESET} "
'!!!WARNING USE WITH CAUTION AS YOU '
"WILL LOSE ALL DATA!!!]\n"
"Are you sure you want to drop the data-backend? ",
default=False,
):
Expand Down
5 changes: 2 additions & 3 deletions plugins/mongodb/superduper_mongodb/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from superduper import logging
from superduper.backends.base.metadata import MetaDataStore
from superduper.components.component import Status
from superduper.misc.colors import Colors


class MongoMetaDataStore(MetaDataStore):
Expand Down Expand Up @@ -61,8 +60,8 @@ def drop(self, force: bool = False):
"""
if not force:
if not click.confirm(
f'{Colors.RED}[!!!WARNING USE WITH CAUTION AS YOU '
f'WILL LOSE ALL DATA!!!]{Colors.RESET} '
'[!!!WARNING USE WITH CAUTION AS YOU '
'WILL LOSE ALL DATA!!!]\n '
'Are you sure you want to drop all meta-data? ',
default=False,
):
Expand Down
5 changes: 2 additions & 3 deletions plugins/sqlalchemy/superduper_sqlalchemy/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from superduper import logging
from superduper.backends.base.metadata import MetaDataStore, NonExistentMetadataError
from superduper.components.component import Status
from superduper.misc.colors import Colors

from superduper_sqlalchemy.db_helper import get_db_config

Expand Down Expand Up @@ -331,8 +330,8 @@ def drop(self, force: bool = False):
"""
if not force:
if not click.confirm(
f'{Colors.RED}[!!!WARNING USE WITH CAUTION AS YOU '
f'WILL LOSE ALL DATA!!!]{Colors.RESET} '
'!!!WARNING USE WITH CAUTION AS YOU '
'WILL LOSE ALL DATA!!!\n '
'Are you sure you want to drop all meta-data? ',
default=False,
):
Expand Down
54 changes: 4 additions & 50 deletions plugins/torch/superduper_torch/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,12 @@
import numpy
import torch
from superduper.components.datatype import BaseDataType, DataTypeFactory
from superduper.ext.numpy.encoder import DecodeArray, EncodeArray
from superduper.ext.utils import str_shape
from superduper.misc.utils import str_shape

if t.TYPE_CHECKING:
pass


class EncodeTensor:
"""Encode a tensor to bytes # noqa.
:param dtype: The dtype of the tensor, eg. torch.float32
"""

def __init__(self, dtype):
self.dtype = dtype

def __call__(self, x, info: t.Optional[t.Dict] = None):
"""Encode a tensor to bytes.
:param x: The tensor to encode.
:param info: Additional information.
"""
if x.dtype != self.dtype:
raise TypeError(f"dtype was {x.dtype}, expected {self.dtype}")
return memoryview(x.numpy()).tobytes()


class DecodeTensor:
"""Decode a tensor from bytes # noqa.
:param dtype: The dtype of the tensor, eg. torch.float32
:param shape: The shape of the tensor, eg. (3, 4)
"""

def __init__(self, dtype, shape):
self.dtype = torch.from_numpy(numpy.random.randn(1).astype(dtype)).dtype
self.shape = shape

def __call__(self, bytes, info: t.Optional[t.Dict] = None):
"""Decode a tensor from bytes.
:param bytes: The bytes to decode.
:param info: Additional information.
"""
array = numpy.frombuffer(bytes, dtype=self.dtype).reshape(self.shape)
return torch.from_numpy(array)


class Tensor(BaseDataType):
"""Encode/ decode a numpy array as bytes.
Expand All @@ -74,19 +32,15 @@ def encode_data(self, item):
:param item: item to encode.
"""
encoder = EncodeArray(self.dtype)
return encoder(item.numpy())
return memoryview(item.numpy()).tobytes()

def decode_data(self, item):
"""Decode data.
:param item: item to decode.
"""
shape = self.shape
if isinstance(shape, int):
shape = (self.shape,)
decoder = DecodeArray(self.dtype, shape=shape)
return torch.from_numpy(decoder(item))
array = numpy.frombuffer(item, dtype=self.dtype).reshape(self.shape)
return torch.from_numpy(array)


class TorchDataTypeFactory(DataTypeFactory):
Expand Down
1 change: 0 additions & 1 deletion superduper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
__version__ = "dev"


from .base.decorators import code
from .base.document import Document
from .base.leaf import imported, imported_value
from .components.application import Application
Expand Down
4 changes: 1 addition & 3 deletions superduper/backends/base/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def release_futures(self, context: str):
"""Release futures from backend."""
pass

# TODO needed?
@property
@abstractmethod
def remote(self) -> bool:
Expand Down Expand Up @@ -89,9 +90,6 @@ def shutdown(self) -> None:
"""Shuts down the compute cluster."""
pass

def execute_task(self, job_id, dependencies, compute_kwargs={}):
"""Execute task function for distributed backends."""

def initialize(self):
"""Connect to address."""

Expand Down
3 changes: 0 additions & 3 deletions superduper/backends/base/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
def _chunked_list(lst, batch_size=BATCH_SIZE):
if len(lst) <= batch_size:
return [lst]

return [lst[i : i + batch_size] for i in range(0, len(lst), batch_size)]


Expand Down Expand Up @@ -118,8 +117,6 @@ class JobFutureException(Exception):
# noqa
"""

...


def consume_streaming_events(events, table, db):
"""
Expand Down
5 changes: 2 additions & 3 deletions superduper/backends/local/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from superduper import logging
from superduper.backends.base.artifacts import ArtifactStore
from superduper.misc.colors import Colors


class FileSystemArtifactStore(ArtifactStore):
Expand Down Expand Up @@ -60,8 +59,8 @@ def drop(self, force: bool = False):
"""
if not force:
if not click.confirm(
f'{Colors.RED}[!!!WARNING USE WITH CAUTION AS YOU '
f'WILL LOSE ALL DATA!!!]{Colors.RESET} '
'!!!WARNING USE WITH CAUTION AS YOU '
'WILL LOSE ALL DATA!!!]\n'
'Are you sure you want to drop all artifacts? ',
default=False,
):
Expand Down
2 changes: 1 addition & 1 deletion superduper/backends/local/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from superduper.backends.local.crontab import LocalCrontabBackend
from superduper.backends.local.queue import LocalQueuePublisher
from superduper.backends.local.vector_search import LocalVectorSearchBackend
from superduper.misc.plugins import load_plugin
from superduper.misc.importing import load_plugin


class LocalCluster(Cluster):
Expand Down
4 changes: 1 addition & 3 deletions superduper/base/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def apply(
object: t.Union['Component', t.Sequence[t.Any], t.Any],
force: bool | None = None,
wait: bool = False,
):
) -> 'Component':
"""
Add functionality in the form of components.
Expand All @@ -36,8 +36,6 @@ def apply(
:param force: List of jobs which should execute before component
initialization begins.
:param wait: Blocks execution till create events finish.
:return: Tuple containing the added object(s) and the original object(s).
"""
if force is None:
force = db.cfg.force_apply
Expand Down
12 changes: 1 addition & 11 deletions superduper/base/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from superduper.base.config import Config
from superduper.base.datalayer import Datalayer
from superduper.misc.anonymize import anonymize_url
from superduper.misc.plugins import load_plugin
from superduper.misc.importing import load_plugin


class _Loader:
Expand Down Expand Up @@ -103,16 +103,6 @@ def _build_metadata(uri):
return db


def _build_compute(cfg):
"""
Helper function to build compute backend.
:param cfg: SuperDuper config.
"""
backend = getattr(load_plugin(cfg.cluster.compute.backend), 'ComputeBackend')
return backend(uri=cfg.cluster.compute.uri, **cfg.cluster.compute.kwargs)


def build_datalayer(cfg=None, **kwargs) -> Datalayer:
"""
Build a Datalayer object as per ``db = superduper(db)`` from configuration.
Expand Down
2 changes: 2 additions & 0 deletions superduper/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class Config(BaseConfig):
:param rest: Settings for rest server.
"""

# TODO make _fold optional

envs: dc.InitVar[t.Optional[t.Dict[str, str]]] = None

data_backend: str = "mongodb://localhost:27017/test_db"
Expand Down
5 changes: 2 additions & 3 deletions superduper/base/datalayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from superduper.components.schema import Schema
from superduper.components.table import Table
from superduper.misc.annotations import deprecated
from superduper.misc.colors import Colors
from superduper.misc.importing import import_object
from superduper.misc.retry import db_retry

Expand Down Expand Up @@ -125,8 +124,8 @@ def drop(self, force: bool = False, data: bool = False):
:param force: Force drop.
"""
if not force and not click.confirm(
f"{Colors.RED}[!!!WARNING USE WITH CAUTION AS YOU WILL"
f"LOSE ALL DATA!!!]{Colors.RESET} "
"!!!WARNING USE WITH CAUTION AS YOU WILL"
"LOSE ALL DATA!!!]\n"
"Are you sure you want to drop the database? ",
default=False,
):
Expand Down
8 changes: 0 additions & 8 deletions superduper/base/decorators.py

This file was deleted.

6 changes: 2 additions & 4 deletions superduper/base/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Getters:
:param getters: A dictionary of getters.
"""

# TODO replace with temporary artifact store.

def __init__(self, getters=None):
self._getters = defaultdict(list)
for k, v in (getters or {}).items():
Expand All @@ -46,10 +48,6 @@ def __init__(self, getters=None):
def add_getter(self, name: str, getter: t.Callable):
"""Add a getter for a reference type."""
self._getters[name].append(getter)
# if name == 'blob':
# self._getters[name].append(_build_blob_getter(getter))
# else:
# self._getters[name].append(getter)

def run(self, name, data):
"""Run the getters one by one until one returns a value."""
Expand Down
2 changes: 2 additions & 0 deletions superduper/base/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO add more exceptions
# for example ArtifactNotFoundError
from superduper import logging


Expand Down
Loading

0 comments on commit 74381a7

Please sign in to comment.