João Francisco
10/31/2024, 2:16 PMfunc_input = inference_api.input.from_arrow(batch)
^^^^^^^^^^^^^^^^^^^
AttributeError: 'APIMethod' object has no attribute 'input'
load_bento can return bentoml._internal.service.service.Service | _bentoml_sdk.service.factory.Service[Any]
While service.Service returns APIs of type InferenceAPI which has input defined, factory.Service returns APIs of type APIMethod, which doesn't have this attribute.Jian Shen Yap
10/31/2024, 2:22 PMJoão Francisco
10/31/2024, 2:23 PMJian Shen Yap
10/31/2024, 2:23 PMJoão Francisco
10/31/2024, 2:39 PMbentoml.Service (old) -> @bentoml.service() (new)) and, running in spark do something like:
import bentoml
import pyspark
from pyspark.sql import SparkSession
from pyspark.sql.types import (
StructType,
StructField,
FloatType,
LongType
)
bento = bentoml.import_bento('/dbfs/mnt/<path_to_you_bento>.bento')
spark = SparkSession.builder.getOrCreate()
schema = StructType([
StructField("col1", FloatType(), True),
StructField("col2", FloatType(), True),
StructField("col3", FloatType(), True),
StructField("col4", FloatType(), True)
])
output_schema = StructType([
StructField("field1", LongType(), True)
])
data = [[5.9, 3.0, 5.1, 1.8],[5.9, 3.0, 5.1, 1.8],[5.9, 3.0, 5.1, 1.8],[5.9, 3.0, 5.1, 1.8]]
# Create a DataFrame
df = spark.createDataFrame(data, schema)
results = run_in_spark(bento, df, spark, output_schema=output_schema)
display(results)João Francisco
10/31/2024, 2:39 PMAttributeError: 'APIMethod' object has no attribute 'input' error I sharedJian Shen Yap
10/31/2024, 2:42 PMJoão Francisco
10/31/2024, 2:43 PMJian Shen Yap
10/31/2024, 2:44 PMJoão Francisco
10/31/2024, 2:46 PMimport bentoml
from typing import Annotated
from bentoml.validators import DataframeSchema
import time
import dill
import pandas as pd
@bentoml.service(
resources={"cpu": "1"},
traffic={"timeout": 10},
)
class MyClass:
def __init__(self) -> None:
# Load inference model
(...)
@bentoml.api
def method(
self,
arg
) -> myReturn:
(..)
return (...)Jian Shen Yap
10/31/2024, 2:47 PMJoão Francisco
10/31/2024, 2:50 PMbentoml._internal.service.service.Service service, which has an input attribute.
However, using the new service structure, we get a _bentoml_sdk.service.factory.Service[Any] service, which doesn't have an input attribute, so func_input = inference_api.input.from_arrow(batch) fails hereJoão Francisco
10/31/2024, 2:54 PMself.input = input_spec
self.output = output_spec
for _bentoml_sdk.service.factory.Service[Any] class.Frost Ming
11/01/2024, 12:55 AMbentoml.Service code. and we haven’t upgrade it yetJoão Francisco
11/01/2024, 2:12 AMFrost Ming
11/01/2024, 2:24 AMFrost Ming
11/01/2024, 2:24 AMJoão Francisco
11/01/2024, 2:02 PMJoão Francisco
11/08/2024, 11:43 AMFrost Ming
11/09/2024, 9:51 AMFrost Ming
11/09/2024, 9:52 AMJoão Francisco
11/11/2024, 10:44 AM