<#5732 [BUG] `TypeEngine.lazy_import_transformers(...
# flytekit
c
#5732 [BUG] `TypeEngine.lazy_import_transformers()` is not thread safe Issue created by Tom-Newton Describe the bug There is a race condition if we try to trigger 2 Flyte executions simultaneously from parallel threads. The race condition is impactful when triggering these executions requires encoders registered by
TypeEngine.lazy_import_transformers()
e.g. if the executions take `StructuredDataset`s as inputs. Resulting error looks something like
Copy code
ValueError: Failed to find a handler for <class 'pandas.core.frame.DataFrame'>, protocol [flyte], fmt ['parquet']
Expected behavior Both executions to be triggered without error. Additional context to reproduce Can reproduce with something like this
Copy code
def run():
    try:
        flyte_remote.execute_remote_task_lp(
        remote_launchplan,
        inputs={
            "dataset": StructuredDataset(dataframe=...),
        },
    )
    except Exception as e:
        _LOGGER.exception("failed_flyte_execution", e)

# Use parallel threads to test a race condition caused by Flyte's TypeEngine.lazy_import_transformers not being
# thread-safe.
t0 = threading.Thread(target=run)
t1 = threading.Thread(target=run)
t0.start()
t1.start()
t0.join()
t1.join()
Screenshots No response Are you sure this issue hasn't been raised already? • Yes Have you read the Code of Conduct? • Yes flyteorg/flyte