truss 0.10.0rc1__py3-none-any.whl → 0.60.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of truss might be problematic. Click here for more details.
- truss/__init__.py +10 -3
- truss/api/__init__.py +123 -0
- truss/api/definitions.py +51 -0
- truss/base/constants.py +116 -0
- truss/base/custom_types.py +29 -0
- truss/{errors.py → base/errors.py} +4 -0
- truss/base/trt_llm_config.py +310 -0
- truss/{truss_config.py → base/truss_config.py} +344 -31
- truss/{truss_spec.py → base/truss_spec.py} +20 -6
- truss/{validation.py → base/validation.py} +60 -11
- truss/cli/cli.py +841 -88
- truss/{remote → cli}/remote_cli.py +2 -7
- truss/contexts/docker_build_setup.py +67 -0
- truss/contexts/image_builder/cache_warmer.py +2 -8
- truss/contexts/image_builder/image_builder.py +1 -1
- truss/contexts/image_builder/serving_image_builder.py +292 -46
- truss/contexts/image_builder/util.py +1 -3
- truss/contexts/local_loader/docker_build_emulator.py +58 -0
- truss/contexts/local_loader/load_model_local.py +2 -2
- truss/contexts/local_loader/truss_module_loader.py +1 -1
- truss/contexts/local_loader/utils.py +1 -1
- truss/local/local_config.py +2 -6
- truss/local/local_config_handler.py +20 -5
- truss/patch/__init__.py +1 -0
- truss/patch/hash.py +4 -70
- truss/patch/signature.py +4 -16
- truss/patch/truss_dir_patch_applier.py +3 -78
- truss/remote/baseten/api.py +308 -23
- truss/remote/baseten/auth.py +3 -3
- truss/remote/baseten/core.py +257 -50
- truss/remote/baseten/custom_types.py +44 -0
- truss/remote/baseten/error.py +4 -0
- truss/remote/baseten/remote.py +369 -118
- truss/remote/baseten/service.py +118 -11
- truss/remote/baseten/utils/status.py +29 -0
- truss/remote/baseten/utils/tar.py +34 -22
- truss/remote/baseten/utils/transfer.py +36 -23
- truss/remote/remote_factory.py +14 -5
- truss/remote/truss_remote.py +72 -45
- truss/templates/base.Dockerfile.jinja +18 -16
- truss/templates/cache.Dockerfile.jinja +3 -3
- truss/{server → templates/control}/control/application.py +14 -35
- truss/{server → templates/control}/control/endpoints.py +39 -9
- truss/{server/control/patch/types.py → templates/control/control/helpers/custom_types.py} +13 -52
- truss/{server → templates/control}/control/helpers/inference_server_controller.py +4 -8
- truss/{server → templates/control}/control/helpers/inference_server_process_controller.py +2 -4
- truss/{server → templates/control}/control/helpers/inference_server_starter.py +5 -10
- truss/{server/control → templates/control/control/helpers}/truss_patch/model_code_patch_applier.py +8 -6
- truss/{server/control/patch → templates/control/control/helpers/truss_patch}/model_container_patch_applier.py +18 -26
- truss/templates/control/control/helpers/truss_patch/requirement_name_identifier.py +66 -0
- truss/{server → templates/control}/control/server.py +11 -6
- truss/templates/control/requirements.txt +9 -0
- truss/templates/custom_python_dx/my_model.py +28 -0
- truss/templates/docker_server/proxy.conf.jinja +42 -0
- truss/templates/docker_server/supervisord.conf.jinja +27 -0
- truss/templates/docker_server_requirements.txt +1 -0
- truss/templates/server/common/errors.py +231 -0
- truss/{server → templates/server}/common/patches/whisper/patch.py +1 -0
- truss/{server/common/patches/__init__.py → templates/server/common/patches.py} +1 -3
- truss/{server → templates/server}/common/retry.py +1 -0
- truss/{server → templates/server}/common/schema.py +11 -9
- truss/templates/server/common/tracing.py +157 -0
- truss/templates/server/main.py +9 -0
- truss/templates/server/model_wrapper.py +961 -0
- truss/templates/server/requirements.txt +21 -0
- truss/templates/server/truss_server.py +447 -0
- truss/templates/server.Dockerfile.jinja +62 -14
- truss/templates/shared/dynamic_config_resolver.py +28 -0
- truss/templates/shared/lazy_data_resolver.py +164 -0
- truss/templates/shared/log_config.py +125 -0
- truss/{server → templates}/shared/secrets_resolver.py +1 -2
- truss/{server → templates}/shared/serialization.py +31 -9
- truss/{server → templates}/shared/util.py +3 -13
- truss/templates/trtllm-audio/model/model.py +49 -0
- truss/templates/trtllm-audio/packages/sigint_patch.py +14 -0
- truss/templates/trtllm-audio/packages/whisper_trt/__init__.py +215 -0
- truss/templates/trtllm-audio/packages/whisper_trt/assets.py +25 -0
- truss/templates/trtllm-audio/packages/whisper_trt/batching.py +52 -0
- truss/templates/trtllm-audio/packages/whisper_trt/custom_types.py +26 -0
- truss/templates/trtllm-audio/packages/whisper_trt/modeling.py +184 -0
- truss/templates/trtllm-audio/packages/whisper_trt/tokenizer.py +185 -0
- truss/templates/trtllm-audio/packages/whisper_trt/utils.py +245 -0
- truss/templates/trtllm-briton/src/extension.py +64 -0
- truss/tests/conftest.py +302 -94
- truss/tests/contexts/image_builder/test_serving_image_builder.py +74 -31
- truss/tests/contexts/local_loader/test_load_local.py +2 -2
- truss/tests/contexts/local_loader/test_truss_module_finder.py +1 -1
- truss/tests/patch/test_calc_patch.py +439 -127
- truss/tests/patch/test_dir_signature.py +3 -12
- truss/tests/patch/test_hash.py +1 -1
- truss/tests/patch/test_signature.py +1 -1
- truss/tests/patch/test_truss_dir_patch_applier.py +23 -11
- truss/tests/patch/test_types.py +2 -2
- truss/tests/remote/baseten/test_api.py +153 -58
- truss/tests/remote/baseten/test_auth.py +2 -1
- truss/tests/remote/baseten/test_core.py +160 -12
- truss/tests/remote/baseten/test_remote.py +489 -77
- truss/tests/remote/baseten/test_service.py +55 -0
- truss/tests/remote/test_remote_factory.py +16 -18
- truss/tests/remote/test_truss_remote.py +26 -17
- truss/tests/templates/control/control/helpers/test_context_managers.py +11 -0
- truss/tests/templates/control/control/helpers/test_model_container_patch_applier.py +184 -0
- truss/tests/templates/control/control/helpers/test_requirement_name_identifier.py +89 -0
- truss/tests/{server → templates/control}/control/test_server.py +79 -24
- truss/tests/{server → templates/control}/control/test_server_integration.py +24 -16
- truss/tests/templates/core/server/test_dynamic_config_resolver.py +108 -0
- truss/tests/templates/core/server/test_lazy_data_resolver.py +329 -0
- truss/tests/templates/core/server/test_lazy_data_resolver_v2.py +79 -0
- truss/tests/{server → templates}/core/server/test_secrets_resolver.py +1 -1
- truss/tests/{server → templates/server}/common/test_retry.py +3 -3
- truss/tests/templates/server/test_model_wrapper.py +248 -0
- truss/tests/{server → templates/server}/test_schema.py +3 -5
- truss/tests/{server/core/server/common → templates/server}/test_truss_server.py +8 -5
- truss/tests/test_build.py +9 -52
- truss/tests/test_config.py +336 -77
- truss/tests/test_context_builder_image.py +3 -11
- truss/tests/test_control_truss_patching.py +7 -12
- truss/tests/test_custom_server.py +38 -0
- truss/tests/test_data/context_builder_image_test/test.py +3 -0
- truss/tests/test_data/happy.ipynb +56 -0
- truss/tests/test_data/model_load_failure_test/config.yaml +2 -0
- truss/tests/test_data/model_load_failure_test/model/__init__.py +0 -0
- truss/tests/test_data/patch_ping_test_server/__init__.py +0 -0
- truss/{test_data → tests/test_data}/patch_ping_test_server/app.py +3 -9
- truss/{test_data → tests/test_data}/server.Dockerfile +20 -21
- truss/tests/test_data/server_conformance_test_truss/__init__.py +0 -0
- truss/tests/test_data/server_conformance_test_truss/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/server_conformance_test_truss/model/model.py +1 -3
- truss/tests/test_data/test_async_truss/__init__.py +0 -0
- truss/tests/test_data/test_async_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_basic_truss/__init__.py +0 -0
- truss/tests/test_data/test_basic_truss/config.yaml +16 -0
- truss/tests/test_data/test_basic_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_build_commands/__init__.py +0 -0
- truss/tests/test_data/test_build_commands/config.yaml +13 -0
- truss/tests/test_data/test_build_commands/model/__init__.py +0 -0
- truss/{test_data/test_streaming_async_generator_truss → tests/test_data/test_build_commands}/model/model.py +2 -3
- truss/tests/test_data/test_build_commands_failure/__init__.py +0 -0
- truss/tests/test_data/test_build_commands_failure/config.yaml +14 -0
- truss/tests/test_data/test_build_commands_failure/model/__init__.py +0 -0
- truss/tests/test_data/test_build_commands_failure/model/model.py +17 -0
- truss/tests/test_data/test_concurrency_truss/__init__.py +0 -0
- truss/tests/test_data/test_concurrency_truss/config.yaml +4 -0
- truss/tests/test_data/test_concurrency_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_custom_server_truss/__init__.py +0 -0
- truss/tests/test_data/test_custom_server_truss/config.yaml +20 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/Dockerfile +17 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/README.md +10 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/VERSION +1 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/__init__.py +0 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/app.py +19 -0
- truss/tests/test_data/test_custom_server_truss/test_docker_image/build_upload_new_image.sh +6 -0
- truss/tests/test_data/test_openai/__init__.py +0 -0
- truss/{test_data/test_basic_truss → tests/test_data/test_openai}/config.yaml +1 -2
- truss/tests/test_data/test_openai/model/__init__.py +0 -0
- truss/tests/test_data/test_openai/model/model.py +15 -0
- truss/tests/test_data/test_pyantic_v1/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v1/model/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v1/model/model.py +28 -0
- truss/tests/test_data/test_pyantic_v1/requirements.txt +1 -0
- truss/tests/test_data/test_pyantic_v2/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v2/config.yaml +13 -0
- truss/tests/test_data/test_pyantic_v2/model/__init__.py +0 -0
- truss/tests/test_data/test_pyantic_v2/model/model.py +30 -0
- truss/tests/test_data/test_pyantic_v2/requirements.txt +1 -0
- truss/tests/test_data/test_requirements_file_truss/__init__.py +0 -0
- truss/tests/test_data/test_requirements_file_truss/config.yaml +13 -0
- truss/tests/test_data/test_requirements_file_truss/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/test_requirements_file_truss/model/model.py +1 -0
- truss/tests/test_data/test_streaming_async_generator_truss/__init__.py +0 -0
- truss/tests/test_data/test_streaming_async_generator_truss/config.yaml +4 -0
- truss/tests/test_data/test_streaming_async_generator_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_async_generator_truss/model/model.py +7 -0
- truss/tests/test_data/test_streaming_read_timeout/__init__.py +0 -0
- truss/tests/test_data/test_streaming_read_timeout/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss/config.yaml +4 -0
- truss/tests/test_data/test_streaming_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_error/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_error/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/test_streaming_truss_with_error/model/model.py +3 -11
- truss/tests/test_data/test_streaming_truss_with_error/packages/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_error/packages/helpers_1.py +5 -0
- truss/tests/test_data/test_streaming_truss_with_error/packages/helpers_2.py +2 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/config.yaml +43 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/model/__init__.py +0 -0
- truss/tests/test_data/test_streaming_truss_with_tracing/model/model.py +65 -0
- truss/tests/test_data/test_trt_llm_truss/__init__.py +0 -0
- truss/tests/test_data/test_trt_llm_truss/config.yaml +15 -0
- truss/tests/test_data/test_trt_llm_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_trt_llm_truss/model/model.py +15 -0
- truss/tests/test_data/test_truss/__init__.py +0 -0
- truss/tests/test_data/test_truss/config.yaml +4 -0
- truss/tests/test_data/test_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_truss/model/dummy +0 -0
- truss/tests/test_data/test_truss/packages/__init__.py +0 -0
- truss/tests/test_data/test_truss/packages/test_package/__init__.py +0 -0
- truss/tests/test_data/test_truss_server_caching_truss/__init__.py +0 -0
- truss/tests/test_data/test_truss_server_caching_truss/model/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/config.yaml +4 -0
- truss/tests/test_data/test_truss_with_error/model/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/model/model.py +8 -0
- truss/tests/test_data/test_truss_with_error/packages/__init__.py +0 -0
- truss/tests/test_data/test_truss_with_error/packages/helpers_1.py +5 -0
- truss/tests/test_data/test_truss_with_error/packages/helpers_2.py +2 -0
- truss/tests/test_docker.py +2 -1
- truss/tests/test_model_inference.py +1340 -292
- truss/tests/test_model_schema.py +33 -26
- truss/tests/test_testing_utilities_for_other_tests.py +50 -5
- truss/tests/test_truss_gatherer.py +3 -5
- truss/tests/test_truss_handle.py +62 -59
- truss/tests/test_util.py +2 -1
- truss/tests/test_validation.py +15 -13
- truss/tests/trt_llm/test_trt_llm_config.py +41 -0
- truss/tests/trt_llm/test_validation.py +91 -0
- truss/tests/util/test_config_checks.py +40 -0
- truss/tests/util/test_env_vars.py +14 -0
- truss/tests/util/test_path.py +10 -23
- truss/trt_llm/config_checks.py +43 -0
- truss/trt_llm/validation.py +42 -0
- truss/truss_handle/__init__.py +0 -0
- truss/truss_handle/build.py +122 -0
- truss/{decorators.py → truss_handle/decorators.py} +1 -1
- truss/truss_handle/patch/__init__.py +0 -0
- truss/{patch → truss_handle/patch}/calc_patch.py +146 -92
- truss/{types.py → truss_handle/patch/custom_types.py} +35 -27
- truss/{patch → truss_handle/patch}/dir_signature.py +1 -1
- truss/truss_handle/patch/hash.py +71 -0
- truss/{patch → truss_handle/patch}/local_truss_patch_applier.py +6 -4
- truss/truss_handle/patch/signature.py +22 -0
- truss/truss_handle/patch/truss_dir_patch_applier.py +87 -0
- truss/{readme_generator.py → truss_handle/readme_generator.py} +3 -2
- truss/{truss_gatherer.py → truss_handle/truss_gatherer.py} +3 -2
- truss/{truss_handle.py → truss_handle/truss_handle.py} +174 -78
- truss/util/.truss_ignore +3 -0
- truss/{docker.py → util/docker.py} +6 -2
- truss/util/download.py +6 -15
- truss/util/env_vars.py +41 -0
- truss/util/log_utils.py +52 -0
- truss/util/path.py +20 -20
- truss/util/requirements.py +11 -0
- {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/METADATA +18 -16
- truss-0.60.0.dist-info/RECORD +324 -0
- {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/WHEEL +1 -1
- truss-0.60.0.dist-info/entry_points.txt +4 -0
- truss_chains/__init__.py +71 -0
- truss_chains/definitions.py +756 -0
- truss_chains/deployment/__init__.py +0 -0
- truss_chains/deployment/code_gen.py +816 -0
- truss_chains/deployment/deployment_client.py +871 -0
- truss_chains/framework.py +1480 -0
- truss_chains/public_api.py +231 -0
- truss_chains/py.typed +0 -0
- truss_chains/pydantic_numpy.py +131 -0
- truss_chains/reference_code/reference_chainlet.py +34 -0
- truss_chains/reference_code/reference_model.py +10 -0
- truss_chains/remote_chainlet/__init__.py +0 -0
- truss_chains/remote_chainlet/model_skeleton.py +60 -0
- truss_chains/remote_chainlet/stub.py +380 -0
- truss_chains/remote_chainlet/utils.py +332 -0
- truss_chains/streaming.py +378 -0
- truss_chains/utils.py +178 -0
- CODE_OF_CONDUCT.md +0 -131
- CONTRIBUTING.md +0 -48
- README.md +0 -137
- context_builder.Dockerfile +0 -24
- truss/blob/blob_backend.py +0 -10
- truss/blob/blob_backend_registry.py +0 -23
- truss/blob/http_public_blob_backend.py +0 -23
- truss/build/__init__.py +0 -2
- truss/build/build.py +0 -143
- truss/build/configure.py +0 -63
- truss/cli/__init__.py +0 -2
- truss/cli/console.py +0 -5
- truss/cli/create.py +0 -5
- truss/config/trt_llm.py +0 -81
- truss/constants.py +0 -61
- truss/model_inference.py +0 -123
- truss/patch/types.py +0 -30
- truss/pytest.ini +0 -7
- truss/server/common/errors.py +0 -100
- truss/server/common/termination_handler_middleware.py +0 -64
- truss/server/common/truss_server.py +0 -389
- truss/server/control/patch/model_code_patch_applier.py +0 -46
- truss/server/control/patch/requirement_name_identifier.py +0 -17
- truss/server/inference_server.py +0 -29
- truss/server/model_wrapper.py +0 -434
- truss/server/shared/logging.py +0 -81
- truss/templates/trtllm/model/model.py +0 -97
- truss/templates/trtllm/packages/build_engine_utils.py +0 -34
- truss/templates/trtllm/packages/constants.py +0 -11
- truss/templates/trtllm/packages/schema.py +0 -216
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/ensemble/config.pbtxt +0 -246
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/postprocessing/1/model.py +0 -181
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/postprocessing/config.pbtxt +0 -64
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/preprocessing/1/model.py +0 -260
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/preprocessing/config.pbtxt +0 -99
- truss/templates/trtllm/packages/tensorrt_llm_model_repository/tensorrt_llm/config.pbtxt +0 -208
- truss/templates/trtllm/packages/triton_client.py +0 -150
- truss/templates/trtllm/packages/utils.py +0 -43
- truss/test_data/context_builder_image_test/test.py +0 -4
- truss/test_data/happy.ipynb +0 -54
- truss/test_data/model_load_failure_test/config.yaml +0 -2
- truss/test_data/test_concurrency_truss/config.yaml +0 -2
- truss/test_data/test_streaming_async_generator_truss/config.yaml +0 -2
- truss/test_data/test_streaming_truss/config.yaml +0 -3
- truss/test_data/test_truss/config.yaml +0 -2
- truss/tests/server/common/test_termination_handler_middleware.py +0 -93
- truss/tests/server/control/test_model_container_patch_applier.py +0 -203
- truss/tests/server/core/server/common/test_util.py +0 -19
- truss/tests/server/test_model_wrapper.py +0 -87
- truss/util/data_structures.py +0 -16
- truss-0.10.0rc1.dist-info/RECORD +0 -216
- truss-0.10.0rc1.dist-info/entry_points.txt +0 -3
- truss/{server/shared → base}/__init__.py +0 -0
- truss/{server → templates/control}/control/helpers/context_managers.py +0 -0
- truss/{server/control → templates/control/control/helpers}/errors.py +0 -0
- truss/{server/control/patch → templates/control/control/helpers/truss_patch}/__init__.py +0 -0
- truss/{server/control/patch → templates/control/control/helpers/truss_patch}/system_packages.py +0 -0
- truss/{test_data/annotated_types_truss/model → templates/server}/__init__.py +0 -0
- truss/{server → templates/server}/common/__init__.py +0 -0
- truss/{test_data/gcs_fix/model → templates/shared}/__init__.py +0 -0
- truss/templates/{trtllm → trtllm-briton}/README.md +0 -0
- truss/{test_data/server_conformance_test_truss/model → tests/test_data}/__init__.py +0 -0
- truss/{test_data/test_basic_truss/model → tests/test_data/annotated_types_truss}/__init__.py +0 -0
- truss/{test_data → tests/test_data}/annotated_types_truss/config.yaml +0 -0
- truss/{test_data/test_requirements_file_truss → tests/test_data/annotated_types_truss}/model/__init__.py +0 -0
- truss/{test_data → tests/test_data}/annotated_types_truss/model/model.py +0 -0
- truss/{test_data → tests/test_data}/auto-mpg.data +0 -0
- truss/{test_data → tests/test_data}/context_builder_image_test/Dockerfile +0 -0
- truss/{test_data/test_truss/model → tests/test_data/context_builder_image_test}/__init__.py +0 -0
- truss/{test_data/test_truss_server_caching_truss/model → tests/test_data/gcs_fix}/__init__.py +0 -0
- truss/{test_data → tests/test_data}/gcs_fix/config.yaml +0 -0
- truss/tests/{local → test_data/gcs_fix/model}/__init__.py +0 -0
- truss/{test_data → tests/test_data}/gcs_fix/model/model.py +0 -0
- truss/{test_data/test_truss/model/dummy → tests/test_data/model_load_failure_test/__init__.py} +0 -0
- truss/{test_data → tests/test_data}/model_load_failure_test/model/model.py +0 -0
- truss/{test_data → tests/test_data}/pima-indians-diabetes.csv +0 -0
- truss/{test_data → tests/test_data}/readme_int_example.md +0 -0
- truss/{test_data → tests/test_data}/readme_no_example.md +0 -0
- truss/{test_data → tests/test_data}/readme_str_example.md +0 -0
- truss/{test_data → tests/test_data}/server_conformance_test_truss/config.yaml +0 -0
- truss/{test_data → tests/test_data}/test_async_truss/config.yaml +0 -0
- truss/{test_data → tests/test_data}/test_async_truss/model/model.py +3 -3
- /truss/{test_data → tests/test_data}/test_basic_truss/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_concurrency_truss/model/model.py +0 -0
- /truss/{test_data/test_requirements_file_truss → tests/test_data/test_pyantic_v1}/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_requirements_file_truss/requirements.txt +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_read_timeout/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_read_timeout/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_truss/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_streaming_truss_with_error/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_truss/examples.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_truss/model/model.py +0 -0
- /truss/{test_data → tests/test_data}/test_truss/packages/test_package/test.py +0 -0
- /truss/{test_data → tests/test_data}/test_truss_server_caching_truss/config.yaml +0 -0
- /truss/{test_data → tests/test_data}/test_truss_server_caching_truss/model/model.py +0 -0
- /truss/{patch → truss_handle/patch}/constants.py +0 -0
- /truss/{notebook.py → util/notebook.py} +0 -0
- {truss-0.10.0rc1.dist-info → truss-0.60.0.dist-info}/LICENSE +0 -0
truss_chains/utils.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import enum
|
|
3
|
+
import inspect
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import random
|
|
7
|
+
import socket
|
|
8
|
+
from typing import Any, Iterable, Iterator, TypeVar, Union
|
|
9
|
+
|
|
10
|
+
from truss_chains import definitions
|
|
11
|
+
|
|
12
|
+
T = TypeVar("T")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def make_abs_path_here(file_path: str) -> definitions.AbsPath:
|
|
16
|
+
"""Helper to specify file paths relative to the *immediately calling* module.
|
|
17
|
+
|
|
18
|
+
E.g. in you have a project structure like this::
|
|
19
|
+
|
|
20
|
+
root/
|
|
21
|
+
chain.py
|
|
22
|
+
common_requirements.text
|
|
23
|
+
sub_package/
|
|
24
|
+
chainlet.py
|
|
25
|
+
chainlet_requirements.txt
|
|
26
|
+
|
|
27
|
+
You can now in ``root/sub_package/chainlet.py`` point to the requirements
|
|
28
|
+
file like this::
|
|
29
|
+
|
|
30
|
+
shared = make_abs_path_here("../common_requirements.text")
|
|
31
|
+
specific = make_abs_path_here("chainlet_requirements.text")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Warning:
|
|
35
|
+
This helper uses the directory of the immediately calling module as an
|
|
36
|
+
absolute reference point for resolving the file location. Therefore,
|
|
37
|
+
you MUST NOT wrap the instantiation of ``make_abs_path_here`` into a
|
|
38
|
+
function (e.g. applying decorators) or use dynamic code execution.
|
|
39
|
+
|
|
40
|
+
Ok::
|
|
41
|
+
|
|
42
|
+
def foo(path: AbsPath):
|
|
43
|
+
abs_path = path.abs_path
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
foo(make_abs_path_here("./somewhere"))
|
|
47
|
+
|
|
48
|
+
Not Ok::
|
|
49
|
+
|
|
50
|
+
def foo(path: str):
|
|
51
|
+
dangerous_value = make_abs_path_here(path).abs_path
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
foo("./somewhere")
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
# TODO: the absolute path resolution below uses the calling module as a
|
|
58
|
+
# reference point. This would not work if users wrap this call in a function
|
|
59
|
+
# - we hope the naming makes clear that this should not be done.
|
|
60
|
+
caller_frame = inspect.stack()[1]
|
|
61
|
+
module_path = caller_frame.filename
|
|
62
|
+
if not os.path.isabs(file_path):
|
|
63
|
+
module_dir = os.path.dirname(os.path.abspath(module_path))
|
|
64
|
+
abs_file_path = os.path.normpath(os.path.join(module_dir, file_path))
|
|
65
|
+
else:
|
|
66
|
+
abs_file_path = file_path
|
|
67
|
+
|
|
68
|
+
return definitions.AbsPath(abs_file_path, module_path, file_path)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def setup_dev_logging(level: Union[int, str] = logging.INFO) -> None:
|
|
72
|
+
root_logger = logging.getLogger()
|
|
73
|
+
root_logger.setLevel(level)
|
|
74
|
+
log_format = "%(levelname)s %(asctime)s %(filename)s:%(lineno)d] %(message)s"
|
|
75
|
+
date_format = "%m%d %H:%M:%S"
|
|
76
|
+
formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
|
|
77
|
+
if root_logger.handlers:
|
|
78
|
+
for handler in root_logger.handlers:
|
|
79
|
+
handler.setFormatter(formatter)
|
|
80
|
+
else:
|
|
81
|
+
handler = logging.StreamHandler()
|
|
82
|
+
handler.setFormatter(formatter)
|
|
83
|
+
root_logger.addHandler(handler)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@contextlib.contextmanager
|
|
87
|
+
def log_level(level: int) -> Iterator[None]:
|
|
88
|
+
"""Change loglevel for code in this context."""
|
|
89
|
+
current_logging_level = logging.getLogger().getEffectiveLevel()
|
|
90
|
+
logging.getLogger().setLevel(level)
|
|
91
|
+
try:
|
|
92
|
+
yield
|
|
93
|
+
finally:
|
|
94
|
+
logging.getLogger().setLevel(current_logging_level)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def expect_one(it: Iterable[T]) -> T:
|
|
98
|
+
"""Assert that an iterable has exactly on element and return it."""
|
|
99
|
+
it = iter(it)
|
|
100
|
+
try:
|
|
101
|
+
element = next(it)
|
|
102
|
+
except StopIteration:
|
|
103
|
+
raise ValueError("Iterable is empty.")
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
_ = next(it)
|
|
107
|
+
except StopIteration:
|
|
108
|
+
return element
|
|
109
|
+
|
|
110
|
+
raise ValueError("Iterable has more than one element.")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def get_free_port() -> int:
|
|
114
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
115
|
+
s.bind(("", 0)) # Bind to a free port provided by the host.
|
|
116
|
+
s.listen(1) # Not necessary but included for completeness.
|
|
117
|
+
port = s.getsockname()[1] # Retrieve the port number assigned.
|
|
118
|
+
return port
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
########################################################################################
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class InjectedError(Exception):
|
|
125
|
+
"""Test error for debugging/dev."""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def random_fail(probability: float, msg: str):
|
|
129
|
+
"""Probabilistically raises `InjectedError` for debugging/dev."""
|
|
130
|
+
if random.random() < probability:
|
|
131
|
+
print(f"Random failure: {msg}")
|
|
132
|
+
raise InjectedError(msg)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class StrEnum(str, enum.Enum):
|
|
136
|
+
"""
|
|
137
|
+
Adapted from MIT-licensed
|
|
138
|
+
https://github.com/irgeek/StrEnum/blob/master/strenum/__init__.py
|
|
139
|
+
|
|
140
|
+
This is useful for Pydantic-based (de-)serialisation, as Pydantic takes the value
|
|
141
|
+
of an enum member as the value to be (de-)serialised, and not the name of the
|
|
142
|
+
member. With this, we can have the member name and value be the same by using
|
|
143
|
+
`enum.auto()`.
|
|
144
|
+
|
|
145
|
+
StrEnum is a Python `enum.Enum` that inherits from `str`. The `auto()` behavior
|
|
146
|
+
uses the member name and lowers it. This is useful for compatibility with pydantic.
|
|
147
|
+
Example usage:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
class Example(StrEnum):
|
|
151
|
+
SOME_VALUE = enum.auto()
|
|
152
|
+
ANOTHER_VALUE = enum.auto()
|
|
153
|
+
TEST = enum.auto()
|
|
154
|
+
|
|
155
|
+
assert Example.SOME_VALUE == "SOME_VALUE"
|
|
156
|
+
assert Example.ANOTHER_VALUE.value == "ANOTHER_VALUE"
|
|
157
|
+
assert Example.TEST.value == Example.TEST
|
|
158
|
+
assert Example.TEST == Example("TEST")
|
|
159
|
+
```
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
def __new__(cls, value, *args, **kwargs):
|
|
163
|
+
if not isinstance(value, str):
|
|
164
|
+
raise TypeError(f"Values of StrEnums must be strings: Got `{repr(value)}`.")
|
|
165
|
+
return super().__new__(cls, value, *args, **kwargs)
|
|
166
|
+
|
|
167
|
+
def __str__(self) -> str:
|
|
168
|
+
return str(self.value)
|
|
169
|
+
|
|
170
|
+
def _generate_next_value_(name, *_) -> str: # type: ignore[override]
|
|
171
|
+
if name.upper() != name:
|
|
172
|
+
raise ValueError(f"Python enum members should be upper case. Got `{name}`.")
|
|
173
|
+
return name
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def issubclass_safe(x: Any, cls: type) -> bool:
|
|
177
|
+
"""Like built-in `issubclass`, but works on non-type objects."""
|
|
178
|
+
return isinstance(x, type) and issubclass(x, cls)
|
CODE_OF_CONDUCT.md
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
-
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
-
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
-
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
-
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
-
identity and orientation.
|
|
11
|
-
|
|
12
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
-
diverse, inclusive, and healthy community.
|
|
14
|
-
|
|
15
|
-
## Our Standards
|
|
16
|
-
|
|
17
|
-
Examples of behavior that contributes to a positive environment for our
|
|
18
|
-
community include:
|
|
19
|
-
|
|
20
|
-
* Demonstrating empathy and kindness toward other people
|
|
21
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
-
* Giving and gracefully accepting constructive feedback
|
|
23
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
-
and learning from the experience
|
|
25
|
-
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
-
community
|
|
27
|
-
|
|
28
|
-
Examples of unacceptable behavior include:
|
|
29
|
-
|
|
30
|
-
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
-
any kind
|
|
32
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
-
* Public or private harassment
|
|
34
|
-
* Publishing others' private information, such as a physical or email address,
|
|
35
|
-
without their explicit permission
|
|
36
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
-
professional setting
|
|
38
|
-
|
|
39
|
-
## Enforcement Responsibilities
|
|
40
|
-
|
|
41
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
-
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
-
or harmful.
|
|
45
|
-
|
|
46
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
-
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
-
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
-
decisions when appropriate.
|
|
50
|
-
|
|
51
|
-
## Scope
|
|
52
|
-
|
|
53
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
-
an individual is officially representing the community in public spaces.
|
|
55
|
-
Examples of representing our community include using an official e-mail address,
|
|
56
|
-
posting via an official social media account, or acting as an appointed
|
|
57
|
-
representative at an online or offline event.
|
|
58
|
-
|
|
59
|
-
## Enforcement
|
|
60
|
-
|
|
61
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
-
reported to the community leaders responsible for enforcement at support@baseten.co.
|
|
63
|
-
All complaints will be reviewed and investigated promptly and fairly.
|
|
64
|
-
|
|
65
|
-
All community leaders are obligated to respect the privacy and security of the
|
|
66
|
-
reporter of any incident.
|
|
67
|
-
|
|
68
|
-
## Enforcement Guidelines
|
|
69
|
-
|
|
70
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
|
71
|
-
the consequences for any action they deem in violation of this Code of Conduct:
|
|
72
|
-
|
|
73
|
-
### 1. Correction
|
|
74
|
-
|
|
75
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
76
|
-
unprofessional or unwelcome in the community.
|
|
77
|
-
|
|
78
|
-
**Consequence**: A private, written warning from community leaders, providing
|
|
79
|
-
clarity around the nature of the violation and an explanation of why the
|
|
80
|
-
behavior was inappropriate. A public apology may be requested.
|
|
81
|
-
|
|
82
|
-
### 2. Warning
|
|
83
|
-
|
|
84
|
-
**Community Impact**: A violation through a single incident or series of
|
|
85
|
-
actions.
|
|
86
|
-
|
|
87
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
|
88
|
-
interaction with the people involved, including unsolicited interaction with
|
|
89
|
-
those enforcing the Code of Conduct, for a specified period of time. This
|
|
90
|
-
includes avoiding interactions in community spaces as well as external channels
|
|
91
|
-
like social media. Violating these terms may lead to a temporary or permanent
|
|
92
|
-
ban.
|
|
93
|
-
|
|
94
|
-
### 3. Temporary Ban
|
|
95
|
-
|
|
96
|
-
**Community Impact**: A serious violation of community standards, including
|
|
97
|
-
sustained inappropriate behavior.
|
|
98
|
-
|
|
99
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
|
100
|
-
communication with the community for a specified period of time. No public or
|
|
101
|
-
private interaction with the people involved, including unsolicited interaction
|
|
102
|
-
with those enforcing the Code of Conduct, is allowed during this period.
|
|
103
|
-
Violating these terms may lead to a permanent ban.
|
|
104
|
-
|
|
105
|
-
### 4. Permanent Ban
|
|
106
|
-
|
|
107
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
|
108
|
-
standards, including sustained inappropriate behavior, harassment of an
|
|
109
|
-
individual, or aggression toward or disparagement of classes of individuals.
|
|
110
|
-
|
|
111
|
-
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
112
|
-
community.
|
|
113
|
-
|
|
114
|
-
## Attribution
|
|
115
|
-
|
|
116
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
117
|
-
version 2.1, available at
|
|
118
|
-
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
119
|
-
|
|
120
|
-
Community Impact Guidelines were inspired by
|
|
121
|
-
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
122
|
-
|
|
123
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
124
|
-
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
125
|
-
[https://www.contributor-covenant.org/translations][translations].
|
|
126
|
-
|
|
127
|
-
[homepage]: https://www.contributor-covenant.org
|
|
128
|
-
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
129
|
-
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
130
|
-
[FAQ]: https://www.contributor-covenant.org/faq
|
|
131
|
-
[translations]: https://www.contributor-covenant.org/translations
|
CONTRIBUTING.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
## Contributing
|
|
2
|
-
|
|
3
|
-
Truss was first created at [Baseten](https://baseten.co), but as an open and living project eagerly accepts contributions of all kinds from the broader developer community. Please note that all participation with Truss falls under our [code of conduct](CODE_OF_CONDUCT.md).
|
|
4
|
-
|
|
5
|
-
We use GitHub features for project management on Truss:
|
|
6
|
-
|
|
7
|
-
* For bugs and feature requests, file an issue.
|
|
8
|
-
* For changes and updates, create a pull request.
|
|
9
|
-
* To view and comment on the roadmap, [check the projects tab](https://github.com/orgs/basetenlabs/projects/3).
|
|
10
|
-
|
|
11
|
-
## Local development
|
|
12
|
-
|
|
13
|
-
To get started contributing to the library, all you have to do is clone this repository!
|
|
14
|
-
|
|
15
|
-
### Setup
|
|
16
|
-
|
|
17
|
-
**PLEASE NOTE:** the ML ecosystem in general is still not well supported on M1 Macs, and as such, we do not recommend or support local development on M1 for Truss. Truss is well-optimized for use with GitHub Codespaces and other container-based development environments.
|
|
18
|
-
|
|
19
|
-
We use `asdf` to manage Python binaries and `poetry` to manage Python dependencies.
|
|
20
|
-
|
|
21
|
-
For development in a macOS environment, we use `brew` to manage system packages.
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
# Install asdf (or use another method https://asdf-vm.com/)
|
|
25
|
-
brew install asdf
|
|
26
|
-
|
|
27
|
-
# Install `asdf` managed python and poetry
|
|
28
|
-
asdf plugin add python
|
|
29
|
-
asdf plugin add poetry
|
|
30
|
-
|
|
31
|
-
# Install poetry dependencies
|
|
32
|
-
poetry install
|
|
33
|
-
|
|
34
|
-
# And finally precommit
|
|
35
|
-
poetry run pre-commit install
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Then to run the entire test suite
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
poetry run pytest truss/tests
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Documentation
|
|
45
|
-
|
|
46
|
-
To learn about Truss see the [official documentation](https://truss.baseten.co).
|
|
47
|
-
|
|
48
|
-
Contributions to documentation are very welcome! Simply edit the appropriate markdown files in the `docs/` folder and make a pull request. For larger changes, tutorials, or any questions please contact [team@trussml.com](mailto:team@trussml.com).
|
README.md
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# Truss
|
|
2
|
-
|
|
3
|
-
**The simplest way to serve AI/ML models in production**
|
|
4
|
-
|
|
5
|
-
[](https://badge.fury.io/py/truss)
|
|
6
|
-
[](https://github.com/basetenlabs/truss/actions/workflows/release.yml)
|
|
7
|
-
|
|
8
|
-
## Why Truss?
|
|
9
|
-
|
|
10
|
-
* **Write once, run anywhere:** Package and test model code, weights, and dependencies with a model server that behaves the same in development and production.
|
|
11
|
-
* **Fast developer loop:** Implement your model with fast feedback from a live reload server, and skip Docker and Kubernetes configuration with a batteries-included model serving environment.
|
|
12
|
-
* **Support for all Python frameworks**: From `transformers` and `diffusers` to `PyTorch` and `TensorFlow` to `TensorRT` and `Triton`, Truss supports models created and served with any framework.
|
|
13
|
-
|
|
14
|
-
See Trusses for popular models including:
|
|
15
|
-
|
|
16
|
-
* 🦙 [Llama 2 7B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-7b-chat) ([13B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-13b-chat)) ([70B](https://github.com/basetenlabs/truss-examples/tree/main/llama/llama-2-70b-chat))
|
|
17
|
-
* 🎨 [Stable Diffusion XL](https://github.com/basetenlabs/truss-examples/tree/main/stable-diffusion/stable-diffusion-xl-1.0)
|
|
18
|
-
* 🗣 [Whisper](https://github.com/basetenlabs/truss-examples/tree/main/whisper/whisper-truss)
|
|
19
|
-
|
|
20
|
-
and [dozens more examples](https://github.com/basetenlabs/truss-examples/).
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
Install Truss with:
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
pip install --upgrade truss
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Quickstart
|
|
31
|
-
|
|
32
|
-
As a quick example, we'll package a [text classification pipeline](https://huggingface.co/docs/transformers/main_classes/pipelines) from the open-source [`transformers` package](https://github.com/huggingface/transformers).
|
|
33
|
-
|
|
34
|
-
### Create a Truss
|
|
35
|
-
|
|
36
|
-
To get started, create a Truss with the following terminal command:
|
|
37
|
-
|
|
38
|
-
```sh
|
|
39
|
-
truss init text-classification
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
When prompted, give your Truss a name like `Text classification`.
|
|
43
|
-
|
|
44
|
-
Then, navigate to the newly created directory:
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
cd text-classification
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Implement the model
|
|
51
|
-
|
|
52
|
-
One of the two essential files in a Truss is `model/model.py`. In this file, you write a `Model` class: an interface between the ML model that you're packaging and the model server that you're running it on.
|
|
53
|
-
|
|
54
|
-
There are two member functions that you must implement in the `Model` class:
|
|
55
|
-
|
|
56
|
-
* `load()` loads the model onto the model server. It runs exactly once when the model server is spun up or patched.
|
|
57
|
-
* `predict()` handles model inference. It runs every time the model server is called.
|
|
58
|
-
|
|
59
|
-
Here's the complete `model/model.py` for the text classification model:
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from transformers import pipeline
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class Model:
|
|
66
|
-
def __init__(self, **kwargs):
|
|
67
|
-
self._model = None
|
|
68
|
-
|
|
69
|
-
def load(self):
|
|
70
|
-
self._model = pipeline("text-classification")
|
|
71
|
-
|
|
72
|
-
def predict(self, model_input):
|
|
73
|
-
return self._model(model_input)
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### Add model dependencies
|
|
77
|
-
|
|
78
|
-
The other essential file in a Truss is `config.yaml`, which configures the model serving environment. For a complete list of the config options, see [the config reference](https://truss.baseten.co/reference/config).
|
|
79
|
-
|
|
80
|
-
The pipeline model relies on [Transformers](https://huggingface.co/docs/transformers/index) and [PyTorch](https://pytorch.org/). These dependencies must be specified in the Truss config.
|
|
81
|
-
|
|
82
|
-
In `config.yaml`, find the line `requirements`. Replace the empty list with:
|
|
83
|
-
|
|
84
|
-
```yaml
|
|
85
|
-
requirements:
|
|
86
|
-
- torch==2.0.1
|
|
87
|
-
- transformers==4.30.0
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
No other configuration is needed.
|
|
91
|
-
|
|
92
|
-
## Deployment
|
|
93
|
-
|
|
94
|
-
Truss is maintained by [Baseten](https://baseten.co), which provides infrastructure for running ML models in production. We'll use Baseten as the remote host for your model.
|
|
95
|
-
|
|
96
|
-
Other remotes are coming soon, starting with AWS SageMaker.
|
|
97
|
-
|
|
98
|
-
### Get an API key
|
|
99
|
-
|
|
100
|
-
To set up the Baseten remote, you'll need a [Baseten API key](https://app.baseten.co/settings/account/api_keys). If you don't have a Baseten account, no worries, just [sign up for an account](https://app.baseten.co/signup/) and you'll be issued plenty of free credits to get you started.
|
|
101
|
-
|
|
102
|
-
### Run `truss push`
|
|
103
|
-
|
|
104
|
-
With your Baseten API key ready to paste when prompted, you can deploy your model:
|
|
105
|
-
|
|
106
|
-
```sh
|
|
107
|
-
truss push
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
You can monitor your model deployment from [your model dashboard on Baseten](https://app.baseten.co/models/).
|
|
111
|
-
|
|
112
|
-
### Invoke the model
|
|
113
|
-
|
|
114
|
-
After the model has finished deploying, you can invoke it from the terminal.
|
|
115
|
-
|
|
116
|
-
**Invocation**
|
|
117
|
-
|
|
118
|
-
```sh
|
|
119
|
-
truss predict -d '"Truss is awesome!"'
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
**Response**
|
|
123
|
-
|
|
124
|
-
```json
|
|
125
|
-
[
|
|
126
|
-
{
|
|
127
|
-
"label": "POSITIVE",
|
|
128
|
-
"score": 0.999873161315918
|
|
129
|
-
}
|
|
130
|
-
]
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## Truss contributors
|
|
134
|
-
|
|
135
|
-
Truss is backed by Baseten and built in collaboration with ML engineers worldwide. Special thanks to [Stephan Auerhahn](https://github.com/palp) @ [stability.ai](https://stability.ai/) and [Daniel Sarfati](https://github.com/dsarfati) @ [Salad Technologies](https://salad.com/) for their contributions.
|
|
136
|
-
|
|
137
|
-
We enthusiastically welcome contributions in accordance with our [contributors' guide](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md).
|
context_builder.Dockerfile
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Builds baseten/truss-context-builder, a light-weight image that can be used
|
|
2
|
-
# for creating docker build context out of a Truss.
|
|
3
|
-
# Build that image as:
|
|
4
|
-
# docker buildx build . -f context_builder.Dockerfile --platform=linux/amd64 -t baseten/truss-context-builder
|
|
5
|
-
FROM python:3.9-slim
|
|
6
|
-
|
|
7
|
-
RUN apt-get update \
|
|
8
|
-
&& apt-get install --yes --no-install-recommends curl tar \
|
|
9
|
-
&& apt-get autoremove -y \
|
|
10
|
-
&& apt-get clean -y \
|
|
11
|
-
&& rm -rf /var/lib/apt/lists/* /tmp/library-scripts/
|
|
12
|
-
|
|
13
|
-
RUN curl -sSL https://install.python-poetry.org | python -
|
|
14
|
-
|
|
15
|
-
ENV PATH="/root/.local/bin:${PATH}"
|
|
16
|
-
COPY ./truss ./truss
|
|
17
|
-
COPY ./pyproject.toml ./pyproject.toml
|
|
18
|
-
COPY ./poetry.lock ./poetry.lock
|
|
19
|
-
COPY ./README.md ./README.md
|
|
20
|
-
|
|
21
|
-
# https://python-poetry.org/docs/configuration/#virtualenvsin-project
|
|
22
|
-
# to write to project root .venv file to be used for context builder test
|
|
23
|
-
RUN poetry config virtualenvs.in-project true \
|
|
24
|
-
&& poetry install --only builder
|
truss/blob/blob_backend.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from typing import Dict
|
|
2
|
-
|
|
3
|
-
from truss.blob.blob_backend import BlobBackend
|
|
4
|
-
from truss.blob.http_public_blob_backend import HttpPublic
|
|
5
|
-
from truss.constants import HTTP_PUBLIC_BLOB_BACKEND
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class _BlobBackendRegistry:
|
|
9
|
-
def __init__(self) -> None:
|
|
10
|
-
self._backends: Dict[str, BlobBackend] = {}
|
|
11
|
-
# Register default backend
|
|
12
|
-
self._backends[HTTP_PUBLIC_BLOB_BACKEND] = HttpPublic()
|
|
13
|
-
|
|
14
|
-
def register_backend(self, name: str, backend: BlobBackend):
|
|
15
|
-
self._backends[name] = backend
|
|
16
|
-
|
|
17
|
-
def get_backend(self, name: str):
|
|
18
|
-
if name not in self._backends:
|
|
19
|
-
raise ValueError(f"Backend {name} is not registered.")
|
|
20
|
-
return self._backends[name]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
BLOB_BACKEND_REGISTRY = _BlobBackendRegistry()
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import shutil
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
|
|
4
|
-
import requests
|
|
5
|
-
from truss.blob.blob_backend import BlobBackend
|
|
6
|
-
|
|
7
|
-
BLOB_DOWNLOAD_TIMEOUT_SECS = 600 # 10 minutes
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class HttpPublic(BlobBackend):
|
|
11
|
-
"""Downloads without auth, files must be publicly available."""
|
|
12
|
-
|
|
13
|
-
def download(self, URL: str, download_to: Path):
|
|
14
|
-
# Streaming download to keep memory usage low
|
|
15
|
-
resp = requests.get(
|
|
16
|
-
URL,
|
|
17
|
-
allow_redirects=True,
|
|
18
|
-
stream=True,
|
|
19
|
-
timeout=BLOB_DOWNLOAD_TIMEOUT_SECS,
|
|
20
|
-
)
|
|
21
|
-
resp.raise_for_status()
|
|
22
|
-
with download_to.open("wb") as file:
|
|
23
|
-
shutil.copyfileobj(resp.raw, file)
|
truss/build/__init__.py
DELETED