

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 限制
<a name="pipelines-step-decorator-limit"></a>

下列各節概述您在針對管道步驟中使用 `@step` 裝飾項目時應注意的限制。

## 函式引數限制
<a name="pipelines-step-decorator-arg"></a>

將輸入引數傳遞至 `@step` 裝飾函式時，適用下列限制：
+ 您可以將 `DelayedReturn`、`Properties` (其他類型的步驟)、`Parameter` 和 `ExecutionVariable` 物件傳遞至 `@step` 裝飾函式做為引數。但是 `@step` 裝飾函式不支援 `JsonGet` 和 `Join` 物件做為引數。
+ 您無法直接從 `@step` 函式存取管道變數。以下範例產生錯誤：

  ```
  param = ParameterInteger(name="{{<parameter-name>}}", default_value=10)
  
  @step
  def func():
      print(param)
  
  func() # this raises a SerializationError
  ```
+ 您無法將一個管道變數套疊另一個物件中，然後將其傳遞至 `@step` 函式。以下範例產生錯誤：

  ```
  param = ParameterInteger(name="{{<parameter-name>}}", default_value=10)
  
  @step
  def func(arg):
      print(arg)
  
  func(arg=(param,)) # this raises a SerializationError because param is nested in a tuple
  ```
+ 由於函式的輸入和輸出是序列化的，因此對可做為函數輸入或輸出傳遞的資料類型有限制。如需詳細資訊，請參閱[調用遠端函式](train-remote-decorator-invocation.md)的*資料序列化和還原序列化*一節。相同的限制適用於 `@step` 裝飾函式。
+ 任何具有 boto 用戶端的物件都無法序列化，因此您無法將這類物件做為輸入傳遞至 `@step` 裝飾函式，也無法將其做為此函式的輸出傳遞。例如，`Estimator`、`Predictor` 和 `Processor` 等 SageMaker Python SDK 用戶端類別無法序列化。

## 函式匯入
<a name="pipelines-step-decorator-best-import"></a>

您應該在函式內匯入步驟所需的程式庫，而不是函數外。如果您在全域範圍內匯入它們，則在序列化函式時您會有發生匯入衝突的風險。例如，`sklearn.pipeline.Pipeline` 可被 `sagemaker.workflow.pipeline.Pipeline` 覆寫。

## 參考函式傳回值的子成員
<a name="pipelines-step-decorator-best-child"></a>

如果您參考 `@step` 裝飾函式傳回值的子成員，則適用下列限制：
+ 如果 `DelayedReturn` 物件代表元組、清單或字典，您可以參考具有 `[]` 的子成員，如下列範例所示：

  ```
  delayed_return[0]
  delayed_return["a_key"]
  delayed_return[1]["a_key"]
  ```
+ 您無法解壓縮元組或清單輸出，因為當您調用函式時，無法得知基礎元組或清單的確切長度。以下範例產生錯誤：

  ```
  a, b, c = func() # this raises ValueError
  ```
+ 您無法逐一查看 `DelayedReturn` 物件。以下範例會引發錯誤：

  ```
  for item in func(): # this raises a NotImplementedError
  ```
+ 您無法參考具有 '`.`' 的任意子成員。以下範例產生錯誤：

  ```
  delayed_return.a_child # raises AttributeError
  ```

## 不支援的現有管道特徵
<a name="pipelines-step-decorator-best-unsupported"></a>

您無法使用 `@step` 裝飾項目搭配下列管道特徵：
+ [管道步驟快取](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-caching.html)
+ [屬性檔案](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-propertyfile.html#build-and-manage-propertyfile-property)