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

feat(python): Enable compression by default #1381

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 1 addition & 16 deletions python/langsmith/_internal/_compressed_runs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import io

Check notice on line 1 in python/langsmith/_internal/_compressed_runs.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

........... create_5_000_run_trees: Mean +- std dev: 586 ms +- 8 ms ........... create_10_000_run_trees: Mean +- std dev: 1.15 sec +- 0.01 sec ........... create_20_000_run_trees: Mean +- std dev: 1.15 sec +- 0.01 sec ........... dumps_class_nested_py_branch_and_leaf_200x400: Mean +- std dev: 705 us +- 8 us ........... dumps_class_nested_py_leaf_50x100: Mean +- std dev: 24.7 ms +- 0.2 ms ........... dumps_class_nested_py_leaf_100x200: Mean +- std dev: 104 ms +- 2 ms ........... dumps_dataclass_nested_50x100: Mean +- std dev: 25.1 ms +- 0.2 ms ........... WARNING: the benchmark result may be unstable * the standard deviation (17.1 ms) is 24% of the mean (71.7 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_pydantic_nested_50x100: Mean +- std dev: 71.7 ms +- 17.1 ms ........... dumps_pydanticv1_nested_50x100: Mean +- std dev: 195 ms +- 3 ms

Check notice on line 1 in python/langsmith/_internal/_compressed_runs.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------------+----------+------------------------+ | Benchmark | main | changes | +===============================================+==========+========================+ | create_10_000_run_trees | 1.46 sec | 1.15 sec: 1.27x faster | +-----------------------------------------------+----------+------------------------+ | create_5_000_run_trees | 739 ms | 586 ms: 1.26x faster | +-----------------------------------------------+----------+------------------------+ | create_20_000_run_trees | 1.44 sec | 1.15 sec: 1.26x faster | +-----------------------------------------------+----------+------------------------+ | dumps_pydanticv1_nested_50x100 | 222 ms | 195 ms: 1.14x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_50x100 | 25.2 ms | 24.7 ms: 1.02x faster | +-----------------------------------------------+----------+------------------------+ | dumps_dataclass_nested_50x100 | 25.4 ms | 25.1 ms: 1.01x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_100x200 | 104 ms | 104 ms: 1.00x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_branch_and_leaf_200x400 | 690 us | 705 us: 1.02x slower | +-----------------------------------------------+----------+------------------------+ | dumps_pydantic_nested_50x100 | 67.6 ms | 71.7 ms: 1.06x slower | +-----------------------------------------------+----------+------------------------+ | Geometric mean | (ref) | 1.09x faster | +-----------------------------------------------+----------+------------------------+

Check notice on line 1 in python/langsmith/_internal/_compressed_runs.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

........... create_5_000_run_trees: Mean +- std dev: 584 ms +- 10 ms ........... create_10_000_run_trees: Mean +- std dev: 1.15 sec +- 0.01 sec ........... create_20_000_run_trees: Mean +- std dev: 1.16 sec +- 0.04 sec ........... dumps_class_nested_py_branch_and_leaf_200x400: Mean +- std dev: 709 us +- 12 us ........... dumps_class_nested_py_leaf_50x100: Mean +- std dev: 25.1 ms +- 0.2 ms ........... dumps_class_nested_py_leaf_100x200: Mean +- std dev: 107 ms +- 6 ms ........... dumps_dataclass_nested_50x100: Mean +- std dev: 25.5 ms +- 0.3 ms ........... WARNING: the benchmark result may be unstable * the standard deviation (16.5 ms) is 23% of the mean (71.2 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_pydantic_nested_50x100: Mean +- std dev: 71.2 ms +- 16.5 ms ........... dumps_pydanticv1_nested_50x100: Mean +- std dev: 198 ms +- 3 ms

Check notice on line 1 in python/langsmith/_internal/_compressed_runs.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------------+----------+------------------------+ | Benchmark | main | changes | +===============================================+==========+========================+ | create_10_000_run_trees | 1.46 sec | 1.15 sec: 1.27x faster | +-----------------------------------------------+----------+------------------------+ | create_5_000_run_trees | 739 ms | 584 ms: 1.27x faster | +-----------------------------------------------+----------+------------------------+ | create_20_000_run_trees | 1.44 sec | 1.16 sec: 1.25x faster | +-----------------------------------------------+----------+------------------------+ | dumps_pydanticv1_nested_50x100 | 222 ms | 198 ms: 1.12x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_50x100 | 25.2 ms | 25.1 ms: 1.00x faster | +-----------------------------------------------+----------+------------------------+ | dumps_dataclass_nested_50x100 | 25.4 ms | 25.5 ms: 1.00x slower | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_100x200 | 104 ms | 107 ms: 1.03x slower | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_branch_and_leaf_200x400 | 690 us | 709 us: 1.03x slower | +-----------------------------------------------+----------+------------------------+ | dumps_pydantic_nested_50x100 | 67.6 ms | 71.2 ms: 1.05x slower | +-----------------------------------------------+----------+------------------------+ | Geometric mean | (ref) | 1.08x faster | +-----------------------------------------------+----------+------------------------+
import threading

try:
from zstandard import ZstdCompressor # type: ignore[import]

HAVE_ZSTD = True
except ImportError:
HAVE_ZSTD = False
from zstandard import ZstdCompressor # type: ignore[import]

from langsmith import utils as ls_utils

Expand All @@ -20,11 +15,6 @@
self.lock = threading.Lock()
self.uncompressed_size = 0

if not HAVE_ZSTD:
raise ImportError(
"zstandard package required for compression. "
"Install with 'pip install langsmith[compression]'"
)
self.compressor_writer = ZstdCompressor(
level=compression_level, threads=-1
).stream_writer(self.buffer, closefd=False)
Expand All @@ -34,11 +24,6 @@
self.run_count = 0
self.uncompressed_size = 0

if not HAVE_ZSTD:
raise ImportError(
"zstandard package required for compression. "
"Install with 'pip install langsmith[compression]'"
)
self.compressor_writer = ZstdCompressor(
level=compression_level, threads=-1
).stream_writer(self.buffer, closefd=False)
8 changes: 4 additions & 4 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ def __init__(
# Create a session and register a finalizer to close it
session_ = session if session else requests.Session()
self.session = session_
if ls_utils.get_env_var("USE_RUN_COMPRESSION"):
if ls_utils.get_env_var("DISABLE_RUN_COMPRESSION"):
self.compressed_runs: Optional[CompressedRuns] = None
else:
self._futures: set[cf.Future] = set()
self.compressed_runs: Optional[CompressedRuns] = CompressedRuns()
self.compressed_runs = CompressedRuns()
self._data_available_event = threading.Event()
else:
self.compressed_runs = None

self._info = (
info
Expand Down
9 changes: 4 additions & 5 deletions python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ requests-toolbelt = "^1.0.0"
# Enabled via `langsmith_pyo3` extra: `pip install langsmith[langsmith_pyo3]`.
langsmith-pyo3 = { version = "^0.1.0rc2", optional = true }
# Enabled via `compression` extra: `pip install langsmith[compression]`.
zstandard = { version = "^0.23.0", optional = true }

[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
Expand Down Expand Up @@ -66,6 +65,7 @@ pytest-socket = "^0.7.0"
pyperf = "^2.7.0"
py-spy = "^0.3.14"
multipart = "^1.0.0"
zstandard = "^0.23.0"

[tool.poetry.group.lint.dependencies]
openai = "^1.10"
Expand All @@ -77,7 +77,6 @@ pytest-socket = "^0.7.0"
[tool.poetry.extras]
vcr = ["vcrpy"]
langsmith_pyo3 = ["langsmith-pyo3"]
compression = ["zstandard"]

[build-system]
requires = ["poetry-core"]
Expand Down
Loading