Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Map task caching failures #2113

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flytekit/core/array_node_map_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@
f = actual_task.lhs
else:
_, mod, f, _ = tracker.extract_task_module(cast(PythonFunctionTask, actual_task).task_function)
sorted_bounded_inputs = ",".join(sorted(self._bound_inputs))

Check warning on line 80 in flytekit/core/array_node_map_task.py

View check run for this annotation

Codecov / codecov/patch

flytekit/core/array_node_map_task.py#L80

Added line #L80 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: could also just turn self._bound_inputs into a sorted list as opposed to set - don't feel too strongly either way

h = hashlib.md5(
f"{collection_interface.__str__()}{concurrency}{min_successes}{min_success_ratio}".encode("utf-8")
f"{sorted_bounded_inputs}{concurrency}{min_successes}{min_success_ratio}".encode("utf-8")
).hexdigest()
self._name = f"{mod}.map_{f}_{h}-arraynode"

Expand Down
3 changes: 2 additions & 1 deletion flytekit/core/map_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
f = actual_task.lhs
else:
_, mod, f, _ = tracker.extract_task_module(typing.cast(PythonFunctionTask, actual_task).task_function)
h = hashlib.md5(collection_interface.__str__().encode("utf-8")).hexdigest()
sorted_bounded_inputs = ",".join(sorted(self._bound_inputs))
h = hashlib.md5(sorted_bounded_inputs.encode("utf-8")).hexdigest()

Check warning on line 96 in flytekit/core/map_task.py

View check run for this annotation

Codecov / codecov/patch

flytekit/core/map_task.py#L95-L96

Added lines #L95 - L96 were not covered by tests
name = f"{mod}.map_{f}_{h}"

self._cmd_prefix: typing.Optional[typing.List[str]] = None
Expand Down
8 changes: 4 additions & 4 deletions tests/flytekit/unit/core/test_array_node_map_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def many_inputs(a: int, b: str, c: float) -> str:
assert m.python_interface.inputs == {"a": List[int], "b": List[str], "c": List[float]}
assert (
m.name
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_4ee240ef5cf979dbc133fb30035cb874-arraynode"
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_bf51001578d0ae197a52c0af0a99dd89-arraynode"
)
r_m = ArrayNodeMapTask(many_inputs)
assert str(r_m.python_interface) == str(m.python_interface)
Expand All @@ -197,7 +197,7 @@ def many_inputs(a: int, b: str, c: float) -> str:
assert m.python_interface.inputs == {"a": List[int], "b": List[str], "c": float}
assert (
m.name
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_352fcdea8523a83134b51bbf5793f14e-arraynode"
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_cb470e880fabd6265ec80e29fe60250d-arraynode"
)
r_m = ArrayNodeMapTask(many_inputs, bound_inputs=set("c"))
assert str(r_m.python_interface) == str(m.python_interface)
Expand All @@ -207,7 +207,7 @@ def many_inputs(a: int, b: str, c: float) -> str:
assert m.python_interface.inputs == {"a": List[int], "b": str, "c": float}
assert (
m.name
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_e224ba3a5b00e08083d541a6ca99b179-arraynode"
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_316e10eb97f5d2abd585951048b807b9-arraynode"
)
r_m = ArrayNodeMapTask(many_inputs, bound_inputs={"c", "b"})
assert str(r_m.python_interface) == str(m.python_interface)
Expand All @@ -217,7 +217,7 @@ def many_inputs(a: int, b: str, c: float) -> str:
assert m.python_interface.inputs == {"a": int, "b": str, "c": float}
assert (
m.name
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_f080e60be9d6faedeef0c74834d6812a-arraynode"
== "tests.flytekit.unit.core.test_array_node_map_task.map_many_inputs_758022acd59ad1c8b81670378d4de4f6-arraynode"
)
r_m = ArrayNodeMapTask(many_inputs, bound_inputs={"a", "c", "b"})
assert str(r_m.python_interface) == str(m.python_interface)
Expand Down
13 changes: 9 additions & 4 deletions tests/flytekit/unit/core/test_map_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,31 +192,36 @@ def many_inputs(a: int, b: str, c: float) -> str:

m = map_task(many_inputs)
assert m.python_interface.inputs == {"a": typing.List[int], "b": typing.List[str], "c": typing.List[float]}
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_24c08b3a2f9c2e389ad9fc6a03482cf9"
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_d41d8cd98f00b204e9800998ecf8427e"
r_m = MapPythonTask(many_inputs)
assert str(r_m.python_interface) == str(m.python_interface)

p1 = functools.partial(many_inputs, c=1.0)
m = map_task(p1)
assert m.python_interface.inputs == {"a": typing.List[int], "b": typing.List[str], "c": float}
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_697aa7389996041183cf6cfd102be4f7"
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_4a8a08f09d37b73795649038408b5f33"
r_m = MapPythonTask(many_inputs, bound_inputs=set("c"))
assert str(r_m.python_interface) == str(m.python_interface)

p2 = functools.partial(p1, b="hello")
m = map_task(p2)
assert m.python_interface.inputs == {"a": typing.List[int], "b": str, "c": float}
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_cc18607da7494024a402a5fa4b3ea5c6"
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_74aefa13d6ab8e4bfbd241583749dfe8"
r_m = MapPythonTask(many_inputs, bound_inputs={"c", "b"})
assert str(r_m.python_interface) == str(m.python_interface)

p3 = functools.partial(p2, a=1)
m = map_task(p3)
assert m.python_interface.inputs == {"a": int, "b": str, "c": float}
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_52fe80b04781ea77ef6f025f4b49abef"
assert m.name == "tests.flytekit.unit.core.test_map_task.map_many_inputs_a44c56c8177e32d3613988f4dba7962e"
r_m = MapPythonTask(many_inputs, bound_inputs={"a", "c", "b"})
assert str(r_m.python_interface) == str(m.python_interface)

p3_1 = functools.partial(p2, a=1)
m_1 = map_task(p3_1)
assert m_1.python_interface.inputs == {"a": int, "b": str, "c": float}
assert m_1.name == m.name

with pytest.raises(TypeError):
m(a=[1, 2, 3])

Expand Down