def test_ray_actor_options_invalid_runtime_env(self, env): # Test invalid runtime_env configurations ray_actor_options_schema = self.get_valid_ray_actor_options_schema() ray_actor_options_schema["runtime_env"] = env with pytest.raises(ValueError): RayActorOptionsSchema.parse_obj(ray_actor_options_schema)
def test_ge_zero_ray_actor_options_schema(self): # Ensure ValidationError is raised when any fields that must be greater # than zero is set to zero. ge_zero_fields = ["num_cpus", "num_gpus", "memory", "object_store_memory"] for field in ge_zero_fields: with pytest.raises(ValidationError): RayActorOptionsSchema.parse_obj({field: -1})
def deployment_to_schema(d: Deployment) -> DeploymentSchema: """Converts a live deployment object to a corresponding structured schema. If the deployment has a class or function, it will be attemptetd to be converted to a valid corresponding import path. init_args and init_kwargs must also be JSON-serializable or this call will fail. """ if d.ray_actor_options is not None: ray_actor_options_schema = RayActorOptionsSchema.parse_obj( d.ray_actor_options) else: ray_actor_options_schema = None return DeploymentSchema( name=d.name, # TODO(Sihan) DeploymentConfig num_replicas and auto_config can be set together # because internally we use these two field for autoscale and deploy. # We can improve the code after we separate the user faced deployment config and # internal deployment config. num_replicas=None if d._config.autoscaling_config else d.num_replicas, route_prefix=d.route_prefix, max_concurrent_queries=d.max_concurrent_queries, user_config=d.user_config, autoscaling_config=d._config.autoscaling_config, graceful_shutdown_wait_loop_s=d._config.graceful_shutdown_wait_loop_s, graceful_shutdown_timeout_s=d._config.graceful_shutdown_timeout_s, health_check_period_s=d._config.health_check_period_s, health_check_timeout_s=d._config.health_check_timeout_s, ray_actor_options=ray_actor_options_schema, )
def deployment_to_schema(d: Deployment) -> DeploymentSchema: """Converts a live deployment object to a corresponding structured schema. If the deployment has a class or function, it will be attemptetd to be converted to a valid corresponding import path. init_args and init_kwargs must also be JSON-serializable or this call will fail. """ if d.ray_actor_options is not None: ray_actor_options_schema = RayActorOptionsSchema.parse_obj( d.ray_actor_options) else: ray_actor_options_schema = None return DeploymentSchema( name=d.name, import_path=get_deployment_import_path(d, enforce_importable=True, replace_main=True), init_args=(), init_kwargs={}, num_replicas=d.num_replicas, route_prefix=d.route_prefix, max_concurrent_queries=d.max_concurrent_queries, user_config=d.user_config, autoscaling_config=d._config.autoscaling_config, graceful_shutdown_wait_loop_s=d._config.graceful_shutdown_wait_loop_s, graceful_shutdown_timeout_s=d._config.graceful_shutdown_timeout_s, health_check_period_s=d._config.health_check_period_s, health_check_timeout_s=d._config.health_check_timeout_s, ray_actor_options=ray_actor_options_schema, )
def test_dict_defaults_ray_actor_options(self): # Dictionary fields should have empty dictionaries as defaults, not None ray_actor_options_schema = {} schema = RayActorOptionsSchema.parse_obj(ray_actor_options_schema) d = schema.dict() assert d["runtime_env"] == {} assert d["resources"] == {}
def test_valid_ray_actor_options_schema(self): # Ensure a valid RayActorOptionsSchema can be generated ray_actor_options_schema = { "runtime_env": { "working_dir": ("https://github.com/shrekris-anyscale/" "test_module/archive/HEAD.zip") }, "num_cpus": 0.2, "num_gpus": 50, "memory": 3, "object_store_memory": 64, "resources": { "custom_asic": 12 }, "accelerator_type": NVIDIA_TESLA_V100, } RayActorOptionsSchema.parse_obj(ray_actor_options_schema)
def test_extra_fields_invalid_ray_actor_options(self): # Undefined fields should be forbidden in the schema ray_actor_options_schema = { "runtime_env": {}, "num_cpus": None, "num_gpus": None, "memory": None, "object_store_memory": None, "resources": {}, "accelerator_type": None, } # Schema should be createable with valid fields RayActorOptionsSchema.parse_obj(ray_actor_options_schema) # Schema should raise error when a nonspecified field is included ray_actor_options_schema["fake_field"] = None with pytest.raises(ValidationError): RayActorOptionsSchema.parse_obj(ray_actor_options_schema)
def test_runtime_env(self): # Test different runtime_env configurations ray_actor_options_schema = { "runtime_env": {}, "num_cpus": 0.2, "num_gpus": 50, "memory": 3, "object_store_memory": 64, "resources": {"custom_asic": 12}, "accelerator_type": NVIDIA_TESLA_V100, } # ray_actor_options_schema should work as is RayActorOptionsSchema.parse_obj(ray_actor_options_schema) # working_dir and py_modules cannot contain local uris ray_actor_options_schema["runtime_env"] = { "working_dir": ".", "py_modules": [ "/Desktop/my_project", ( "https://github.com/shrekris-anyscale/" "test_deploy_group/archive/HEAD.zip" ), ], } with pytest.raises(ValueError): RayActorOptionsSchema.parse_obj(ray_actor_options_schema) # remote uris should work ray_actor_options_schema["runtime_env"] = { "working_dir": ( "https://github.com/shrekris-anyscale/test_module/archive/HEAD.zip" ), "py_modules": [ ( "https://github.com/shrekris-anyscale/" "test_deploy_group/archive/HEAD.zip" ), ], } RayActorOptionsSchema.parse_obj(ray_actor_options_schema)
def test_ray_actor_options_valid_runtime_env(self, env): # Test valid runtime_env configurations ray_actor_options_schema = self.get_valid_ray_actor_options_schema() ray_actor_options_schema["runtime_env"] = env RayActorOptionsSchema.parse_obj(ray_actor_options_schema)
def test_valid_ray_actor_options_schema(self): # Ensure a valid RayActorOptionsSchema can be generated ray_actor_options_schema = self.get_valid_ray_actor_options_schema() RayActorOptionsSchema.parse_obj(ray_actor_options_schema)