AttributeError: 'ParameterString' object has no attribute 'startswith'
dilky-ascentic opened this issue · comments
I am trying to run this tutorial as it is and always run into AttributeError: 'ParameterString' object has no attribute 'startswith'
, when json.loads(pipeline.definition())
is executed.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-32-d1b69f80bc6f> in <module>
1 import json
2
----> 3 json.loads(pipeline.definition())
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/pipeline.py in definition(self)
319 def definition(self) -> str:
320 """Converts a request structure to string representation for workflow service calls."""
--> 321 request_dict = self.to_request()
322 self._interpolate_step_collection_name_in_depends_on(request_dict["Steps"])
323 request_dict["PipelineExperimentConfig"] = interpolate(
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/pipeline.py in to_request(self)
103 if self.pipeline_experiment_config is not None
104 else None,
--> 105 "Steps": list_to_request(self.steps),
106 }
107
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/utilities.py in list_to_request(entities)
51 for entity in entities:
52 if isinstance(entity, Entity):
---> 53 request_dicts.append(entity.to_request())
54 elif isinstance(entity, StepCollection):
55 request_dicts.extend(entity.request_dicts())
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/steps.py in to_request(self)
497 def to_request(self) -> RequestType:
498 """Updates the request dictionary with cache configuration."""
--> 499 request_dict = super().to_request()
500 if self.cache_config:
501 request_dict.update(self.cache_config.config)
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/steps.py in to_request(self)
349 def to_request(self) -> RequestType:
350 """Gets the request structure for `ConfigurableRetryStep`."""
--> 351 step_dict = super().to_request()
352 if self.retry_policies:
353 step_dict["RetryPolicies"] = self._resolve_retry_policy(self.retry_policies)
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/steps.py in to_request(self)
118 "Name": self.name,
119 "Type": self.step_type.value,
--> 120 "Arguments": self.arguments,
121 }
122 if self.depends_on:
/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/steps.py in arguments(self)
478 self.estimator._prepare_for_training(self.job_name)
479 train_args = _TrainingJob._get_train_args(
--> 480 self.estimator, self.inputs, experiment_config=dict()
481 )
482 request_dict = self.estimator.sagemaker_session._get_train_request(**train_args)
/opt/conda/lib/python3.7/site-packages/sagemaker/estimator.py in _get_train_args(cls, estimator, inputs, experiment_config)
2038 train_args = config.copy()
2039 train_args["input_mode"] = estimator.input_mode
-> 2040 train_args["job_name"] = estimator._current_job_name
2041 train_args["hyperparameters"] = hyperparameters
2042 train_args["tags"] = estimator.tags
/opt/conda/lib/python3.7/site-packages/sagemaker/estimator.py in training_image_uri(self, region)
3034 trains the model, calls this method to find the hyperparameters.
3035
-> 3036 Returns:
3037 dict[str, str]: The hyperparameters.
3038 """
/opt/conda/lib/python3.7/site-packages/sagemaker/image_uris.py in get_training_image_uri(region, framework, framework_version, py_version, image_uri, distribution, compiler_config, tensorflow_version, pytorch_version, instance_type)
497
498 if tensorflow_version is not None or pytorch_version is not None:
--> 499 processor = _processor(instance_type, ["cpu", "gpu"])
500 is_native_huggingface_gpu = processor == "gpu" and not compiler_config
501 container_version = "cu110-ubuntu18.04" if is_native_huggingface_gpu else None
/opt/conda/lib/python3.7/site-packages/sagemaker/image_uris.py in _processor(instance_type, available_processors, serverless_inference_config)
366 )
367
--> 368 if instance_type.startswith("local"):
369 processor = "cpu" if instance_type == "local" else "gpu"
370 elif instance_type.startswith("neuron"):
AttributeError: 'ParameterString' object has no attribute 'startswith'
Converting ParameterString
to str
like,
pipeline = Pipeline(
name=f"HuggingFaceDemoPipeline",
parameters=[
str(model_id),
str(dataset_name),
str(processing_instance_type),
processing_instance_count,
processing_script,
training_entry_point,
training_source_dir,
training_instance_type,
training_instance_count,
evaluation_script,
threshold_accuracy,
epochs,
eval_batch_size,
train_batch_size,
learning_rate,
fp16
],
steps=[step_process, step_train, step_eval, step_cond],
sagemaker_session=sagemaker_session,
)
results in TypeError: Pipeline variables do not support __str__ operation. Please use
.to_string()to convert it to string type in execution timeor use
.expr to translate it to Json for display purpose in Python SDK.
Is there a way to solve this?
It seems that the error is coming from the sagemaker-sdk
itself and was introduced in the past.
Could you open an issue in https://github.com/aws/sagemaker-python-sdk?
As a workaround, you could try installing sagemaker==2.48.0
, since that's the version which we used for the workshop
I was able to solve the issue by installing sagemaker==2.77.1
on Pytorch 1.10 Python 3.8 CPU Optimized
notebook environment.