{"record":{"id":"b07955bfd55d48c4","repo":"tensorflow/models","slug":"failed-to-clean-up-temporarydirectory","errorCode":null,"errorMessage":"Failed to clean up TemporaryDirectory","messagePattern":"Failed to clean up TemporaryDirectory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"official/nlp/tools/export_tfhub_lib.py","lineNumber":429,"sourceCode":"                         tokenize_with_offsets: bool,\n                         default_seq_length: int,\n                         experimental_disable_assert: bool = False) -> None:\n  \"\"\"Exports preprocessing to a SavedModel for TF Hub.\"\"\"\n  with tempfile.TemporaryDirectory() as tmpdir:\n    # TODO(b/175369555): Remove experimental_disable_assert and its use.\n    with _maybe_disable_assert(experimental_disable_assert):\n      preprocessing = create_preprocessing(\n          vocab_file=_move_to_tmpdir(vocab_file, tmpdir),\n          sp_model_file=_move_to_tmpdir(sp_model_file, tmpdir),\n          do_lower_case=do_lower_case,\n          tokenize_with_offsets=tokenize_with_offsets,\n          default_seq_length=default_seq_length)\n      preprocessing.save(export_path, include_optimizer=False, save_format=\"tf\")\n    if experimental_disable_assert:\n      _check_no_assert(export_path)\n  # It helps the unit test to prevent stray copies of the vocab file.\n  if tf.io.gfile.exists(tmpdir):\n    raise IOError(\"Failed to clean up TemporaryDirectory\")\n\n\n# TODO(b/175369555): Remove all workarounds for this bug of TensorFlow 2.4\n# when this bug is no longer a concern for publishing new models.\n# TensorFlow 2.4 has a placement issue with Assert ops in tf.functions called\n# from Dataset.map() on a TPU worker. They end up on the TPU coordinator,\n# and invoking them from the TPU worker is either inefficient (when possible)\n# or impossible (notably when using \"headless\" TPU workers on Cloud that do not\n# have a channel to the coordinator). The bug has been fixed in time for TF 2.5.\n# To work around this, the following code avoids Assert ops in the exported\n# SavedModels. It monkey-patches calls to tf.Assert from inside TensorFlow and\n# replaces them by a no-op while building the exported model. This is fragile,\n# so _check_no_assert() validates the result. The resulting model should be fine\n# to read on future versions of TF, even if this workaround at export time\n# may break eventually. (Failing unit tests will tell.)\n\n\ndef _dont_assert(condition, data, summarize=None, name=\"Assert\"):","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/tools/export_tfhub_lib.py#L411-L447","documentation":"Error \"Failed to clean up TemporaryDirectory\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/tools/export_tfhub_lib.py:429 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"}