Skip to content
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

add posthog #410

Merged
merged 7 commits into from
Oct 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion docs/assets/openapi.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/docs/cli_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ $ infinity_emb v2 --help
│ `INFINITY_LENGTHS_VIA_TOKENIZ… │
│ [default: │
│ lengths-via-tokenize] │
│ --dtype [float32|float16|int8|fp8|aut dtype for the model weights. │
o] [env var: `INFINITY_DTYPE`] │
│ --dtype [float32|float16|bfloat16|int dtype for the model weights. │
8|fp8|auto] [env var: `INFINITY_DTYPE`] │
│ [default: auto] │
│ --embedding-dtype [float32|int8|uint8|binary|ub dtype post-forward pass. If != │
│ inary] `float32`, using Post-Forward │
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Telemetry

All CLI arguments are currently logged, as well as system info such as os.
The feedback will be used to optimzed common models / OS support.

## Disable Telemetry
You can disable tracking like the following:

```
# set
export DO_NOT_TRACK="1"
# infinity specific setting
export INFINITY_ANONYMOUS_USAGE_STATS="0"
```

or by CLI argument.
2 changes: 1 addition & 1 deletion libs/client_infinity/infinity_client/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "infinity_client"
version = "0.0.62"
version = "0.0.63"
description = "A client library for accessing ♾️ Infinity - Embedding Inference Server"
authors = []
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion libs/infinity_emb/infinity_emb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from infinity_emb.log_handler import logger # noqa: E402
from infinity_emb.sync_engine import SyncEngineArray # noqa: E402

__version__ = importlib.metadata.version("infinity_emb")
__version__: str = importlib.metadata.version("infinity_emb")

__all__ = [
"__version__",
Expand Down
1 change: 1 addition & 0 deletions libs/infinity_emb/infinity_emb/_optional_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _raise_error(self) -> None:
CHECK_TRANSFORMERS = OptionalImports("transformers", "torch")
CHECK_TORCH = OptionalImports("torch.nn", "torch")
# CHECK_REQUESTS = OptionalImports("requests", "server")
CHECK_POSTHOG = OptionalImports("posthog", "server")
CHECK_AIOHTTP = OptionalImports("aiohttp", "server")
CHECK_PIL = OptionalImports("PIL", "vision")
CHECK_SOUNDFILE = OptionalImports("soundfile", "audio")
Expand Down
13 changes: 12 additions & 1 deletion libs/infinity_emb/infinity_emb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _optional_infinity_var_multiple(

@staticmethod
def _to_bool(value: str) -> bool:
return value.lower() in {"true", "1"}
return value.lower() in {"true", "1", "yes", "y"}

@staticmethod
def _to_bool_multiple(value: list[str]) -> list[bool]:
Expand Down Expand Up @@ -153,6 +153,17 @@ def calibration_dataset_url(self):
default="https://raw.githubusercontent.com/michaelfeil/infinity/2da1f32d610b8edbe4ce58d0c44fc27c963abca6/docs/assets/multilingual_calibration.utf8",
)

@cached_property
def anonymous_usage_stats(self):
tracking_allowed = self._to_bool(
self._optional_infinity_var(
"anonymous_usage_stats",
default="true",
)
)
tracking_allowed_2 = not self._to_bool(os.getenv("DO_NOT_TRACK", "0"))
return tracking_allowed and tracking_allowed_2

@cached_property
def cache_dir(self) -> Path:
"""gets the cache directory for infinity_emb."""
Expand Down
26 changes: 26 additions & 0 deletions libs/infinity_emb/infinity_emb/infinity_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import signal
import sys
import time
import uuid
from contextlib import asynccontextmanager
from typing import Any, Optional, Union

Expand Down Expand Up @@ -36,9 +37,11 @@
ImageCorruption,
InferenceEngine,
Modality,
ModelCapabilites,
ModelNotDeployedError,
PoolingMethod,
)
from infinity_emb.telemetry import PostHog, StartupTelemetry


def create_server(
Expand All @@ -61,10 +64,32 @@ def create_server(
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from prometheus_fastapi_instrumentator import Instrumentator

def send_telemetry_start(
engine_args_list: list[EngineArgs],
capabilities_list: list[set[ModelCapabilites]],
):
session_id = uuid.uuid4().hex
for arg, capabilities in zip(engine_args_list, capabilities_list):
PostHog.capture(
StartupTelemetry(
engine_args=arg,
num_engines=len(engine_args_list),
capabilities=capabilities,
session_id=session_id,
)
)

@asynccontextmanager
async def lifespan(app: FastAPI):
instrumentator.expose(app) # type: ignore
app.engine_array = AsyncEngineArray.from_args(engine_args_list) # type: ignore
asyncio.create_task(
asyncio.to_thread(
send_telemetry_start,
engine_args_list,
[e.capabilities for e in app.engine_array], # type: ignore
)
)
# start in a threadpool
await app.engine_array.astart() # type: ignore

Expand All @@ -87,6 +112,7 @@ async def kill_later(seconds: int):
" -> exit ."
)
asyncio.create_task(kill_later(3))

yield
await app.engine_array.astop() # type: ignore
# shutdown!
Expand Down
3 changes: 2 additions & 1 deletion libs/infinity_emb/infinity_emb/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ClassifyReturnType(TypedDict):
UnionReturnType = Union[EmbeddingReturnType, ReRankReturnType, ClassifyReturnType]


class EnumType(enum.Enum):
class EnumType(str, enum.Enum):
@classmethod
@lru_cache
def names_enum(cls) -> enum.Enum:
Expand Down Expand Up @@ -125,6 +125,7 @@ def resolve(self) -> Optional[str]:
class Dtype(EnumType):
float32: str = "float32"
float16: str = "float16"
bfloat16: str = "bfloat16"
int8: str = "int8"
fp8: str = "fp8"
auto: str = "auto"
Expand Down
Loading
Loading