{"record":{"id":"4438dbc5e4850ddb","repo":"tensorflow/models","slug":"steps-should-be-an-tensor-python-object-may-cause-4438db","errorCode":null,"errorMessage":"steps should be an Tensor. Python object may cause retracing.","messagePattern":"steps should be an Tensor\\. Python object may cause retracing\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/detection/executor/distributed_executor.py","lineNumber":285,"sourceCode":"    Returns:\n      The training step callable.\n    \"\"\"\n    replicated_step = self._create_replicated_step(strategy, model, loss_fn,\n                                                   optimizer, metric)\n\n    @tf.function\n    def train_step(iterator, num_steps):\n      \"\"\"Performs a distributed training step.\n\n      Args:\n        iterator: an iterator that yields input tensors.\n        num_steps: the number of steps in the loop.\n\n      Returns:\n        The loss tensor.\n      \"\"\"\n      if not isinstance(num_steps, tf.Tensor):\n        raise ValueError('steps should be an Tensor. Python object may cause '\n                         'retracing.')\n\n      per_replica_losses = strategy.run(replicated_step, args=(next(iterator),))\n      for _ in tf.range(num_steps - 1):\n        per_replica_losses = strategy.run(\n            replicated_step, args=(next(iterator),))\n\n      # For reporting, we returns the mean of losses.\n      losses = tf.nest.map_structure(\n          lambda x: strategy.reduce(tf.distribute.ReduceOp.MEAN, x, axis=None),\n          per_replica_losses)\n      return losses\n\n    return train_step\n\n  def _create_test_step(self, strategy, model, metric):\n    \"\"\"Creates a distributed test step.\"\"\"\n    metrics = metrics_as_dict(metric)","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/detection/executor/distributed_executor.py#L267-L303","documentation":"Error \"steps should be an Tensor. Python object may cause retracing.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/detection/executor/distributed_executor.py:285 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}