Hi,
I keep getting this error: AttributeError: module 'sagemaker' has no attribute 'create_transform_job', when using a batch transform example that AWS graciously had in the notebook instances. Code:
***Also, I updated Sagemaker to the newest package and its still not working.
%%time
import time
from time import gmtime, strftime
batch_job_name = "Batch-Transform-" + strftime("%Y-%m-%d-%H-%M-%S", gmtime())
input_location = "s3://{}/{}/batch/{}".format(
bucket, prefix, batch_file
) # use input data without ID column
output_location = "s3://{}/{}/output/{}".format(bucket, prefix, batch_job_name)
request = {
"TransformJobName": batch_job_name,
"ModelName": 'xgboost-parquet-example-training-2022-03-28-16-02-31-model',
"TransformOutput": {
"S3OutputPath": output_location,
"Accept": "text/csv",
"AssembleWith": "Line",
},
"TransformInput": {
"DataSource": {"S3DataSource": {"S3DataType": "S3Prefix", "S3Uri": input_location}},
"ContentType": "text/csv",
"SplitType": "Line",
"CompressionType": "None",
},
"TransformResources": {"InstanceType": "ml.m4.xlarge", "InstanceCount": 1},
}
sagemaker.create_transform_job(**request)
print("Created Transform job with name: ", batch_job_name)
# Wait until the job finishes
try:
sagemaker.get_waiter("transform_job_completed_or_stopped").wait(TransformJobName=batch_job_name)
finally:
response = sagemaker.describe_transform_job(TransformJobName=batch_job_name)
status = response["TransformJobStatus"]
print("Transform job ended with status: " + status)
if status == "Failed":
message = response["FailureReason"]
print("Transform failed with the following error: {}".format(message))
raise Exception("Transform job failed")
Everything else is working well. I've had no luck with this on anyother forum.
To add to the answer, if you're using the SageMaker Python SDK (since you mentioned 'updated sagemaker package', use the transformer API - https://sagemaker.readthedocs.io/en/stable/api/inference/transformer.html
To use create_transform_job(), you need a SageMaker boto3 client.