a `@card`'s `render` method is only triggered for ...
# ask-metaflow
n
a `@card`'s
render
method is only triggered for successful steps, if I understand correctly -- is there any way to render a card even after a step failed?
āœ… 1
a
there is no guarantee that we will have runtime available for the render method to execute - say an oomkilled, segfault etc.
n
that's fine šŸ‘ but as per my understanding, the card renders the HTML in a separate process anyway, and I'm not worried about edge cases. maybe an example helps explaining what I am looking for: using the HTML-card extension, I want to make the card available even if the step fails, e.g.
Copy code
card(type='html')
@step
def train(self):
    self.html = "foobar"
    error
this results in a failed step, without the HTML card rendered .. while it could be useful to render it. I understand the above could be solved by using a
blank
card type and calling
append
and `refresh`on it before the error .. but I wonder if forcing the rendering of card without realtime updates is achievable somehow
it seems that the
render
is already running in the
task_finished
method and not in the
task_post_step
, and it's only filtered out at https://github.com/Netflix/metaflow/blob/master/metaflow/plugins/cards/card_decorator.py#L268 by checking the status of the step .. so I wonder if it would be possible to make that check optional e.g. via
card
attributes/configs and optionally render the card on failed steps as well šŸ¤” any thoughts?
h
Metaflow has support for realtime cards but a lot of the external cards (like html card/ notebook card) dont have realtime cards support. You can make a card realtime by doing the following: 1. You need to set the MetaflowCard.REALTIME_UPDATABLE to `True`: You will have to change it's reload_policy to what ever suits the Usecase. This explains the different modes taken by the reload policy 2. You need to implement some of the method's in the MetaflowCard : like
render_runtime
,
reload_token
,
refresh
a. These is an example card here . The usage of this card is present here This way you can render the card before runtime and during runtime so that covers the failure case too. Currently there is no explicit callback on failure.
šŸ‘€ 1
n
Thanks a ton, @little-apartment-49355 -- this was super helpful!! šŸ™‡ It took some time to think this through and come up with a hack so that I can render my card even if the step fails, especially that the card is an injected decorator of a step decorator's
step_init
, but I think I got this working. Sharing here if others might find it useful in the future when searching for something like this: https://github.com/SpareCores/resource-tracker/commit/7c7b2312ae21d45c925992d96d38308d6a23a1e1, but in short: • storing the artifacts needed for the card in the
task_exception
, just like I did in the
task_post_step
method in the past • implemented the
task_finished
method mimicking the `CardDecorator`'s
task_finished
method without checking for the step's status, so basically rendering the card And this is it .. it works, but there a few minor caveats, like the standard Metaflow client cannot find the stored artifacts (e.g. via
Flow(...).latest_run.data
) or cards (e.g. via
get_cards
), but the Metaflow CLI can find on disk, so had to use that in the related unit tests to check if the card was indeed created -- I hope I'm not touching anything highly breakable (e.g. with future Metaflow versions) with this approach.