Migration from Flyte 1 to Flyte 2
Automated migration from Flyte 1 to Flyte 2 is coming soon.
Flyte 2 will soon offer automated migration from Flyte 1 to 2.
In the meantime you can migrate manually by following the steps below.:
1. Move task configuration to a TaskEnvironment object
Instead of configuring the image, hardware resources, and so forth, directly in the task decorator. You configure it in TaskEnvironment object. For example:
env = flyte.TaskEnvironment(name="my_task_env")2. Replace workflow decorators
Then, you replace the @workflow and @task decorators with @env.task decorators.
Here’s a simple hello world example with fan-out.
import flytekit
@flytekit.task
def hello_world(name: str) -> str:
return f"Hello, {name}!"
@flytekit.workflow
def main(names: list[str]) -> list[str]:
return flytekit.map(hello_world)(names)Change all the decorators to @env.task and swap out flytekit.map with flyte.map.
Notice that flyte.map is a drop-in replacement for Python’s built-in map function.
[email protected]
[email protected]
def hello_world(name: str) -> str:
return f"Hello, {name}!"
[email protected]
[email protected]
def main(names: list[str]) -> list[str]:
return flyte.map(hello_world, names)
env is simply because that is the variable to which we assigned the TaskEnvironment above.To take advantage of full concurrency (not just parallelism), use Python async
syntax and the asyncio standard library to implement fa-out.
+import asyncio
@env.task
-def hello_world(name: str) -> str:
+async def hello_world(name: str) -> str:
return f"Hello, {name}!"
@env.task
-def main(names: list[str]) -> list[str]:
+async def main(names: list[str]) -> list[str]:
- return flyte.map(hello_world, names)
+ return await asyncio.gather(*[hello_world(name) for name in names])
To use Python async syntax, you need to:
- Use
asyncio.gather()orflyte.map()for parallel execution - Add
async/awaitkeywords where you want parallelism - Keep existing sync task functions unchanged
Learn more about about the benefits of async in the Asynchronous Model guide.
3. Leverage enhanced capabilities
- Add conditional logic and loops within workflows
- Implement proper error handling with try/except
- Create dynamic workflows that adapt to runtime conditions