Skip to content

[card] current.card.copy [exploratory] #2337

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valayDave
Copy link
Collaborator

Usecases

  • Assume that a user has trained a model in train @step and was using that trained model in the test @step. The train step produced a card that was relevant to the model being used in the test step. Now when user visits the MF gui to see the test step cards, there are no cards for the model. If the user wishes to see the card for the model, then the user has the re-create the model card in the test step or go to the train task and see the model.

  • Assume that the user is training many models in a foreach, the join step chooses the best model. The foreach ended up creating many different model cards. But if the user wishes to see the card for the best step, then they have to find the task on the MF gui corresponding to the the best model

Potential ways of tackling the usecase.

  • We provide a way to create references for other cards between tasks (adding more "logical" machinery to cards / complexity)
  • Do the dumb thing. Copy the necessary cards over where required.

current changes

  • cli command to copy cards from other tasks

  • Exposing the interface in current.card so that cards can be copied over during runtime. This also allows users the flexibility to select which cards to copy during runtime.

  • useful for the cases when users need to showcase the model card in downstream steps without having to re-render the card everytime.

  • Example flow:

from metaflow import FlowSpec, step, card, current

class CardCopyTestFlow(FlowSpec):
    """
    A flow that demonstrates the card copy functionality.
    """

    @card(type="blank")
    @step
    def start(self):
        """
        Create a card in the start step.
        """
        from metaflow.cards import Markdown
        current.card.append(Markdown("# Original Card"))
        current.card.append(Markdown("This card was created in the start step."))
        self.pathspec = current.pathspec
        self.next(self.copy_card)

    @card(type="blank")
    @step
    def copy_card(self):
        """
        Copy the card from the start step.
        """
        from metaflow.cards import Markdown

        # First, create a new card for this step
        current.card.append(Markdown("# Destination Card"))
        current.card.append(Markdown("This card was created in the copy_card step."))

        # Now, copy the card from the start step
        # Get the pathspec for the start step

        # Copy the card from the start step
        success = current.card.copy(self.pathspec)

        if success:
            current.card.append(Markdown("## Card Copy Success"))
            current.card.append(Markdown(f"Successfully copied card from {self.pathspec}"))
        else:
            current.card.append(Markdown("## Card Copy Failed"))
            current.card.append(Markdown(f"Failed to copy card from {self.pathspec}"))

        self.next(self.end)

    @step
    def end(self):
        """
        End the flow.
        """
        print("Flow completed successfully!")

if __name__ == "__main__":
    CardCopyTestFlow()

- cli command to copy cards from other tasks
- Exposing the interface in `current.card` so that cards can be copied over during runtime. This also allows users the flexibility to select which cards to copy during runtime.
- useful for the cases when users need to showcase the model card in downstream steps without having to re-render the card everytime.

- Example flow:
```python
from metaflow import FlowSpec, step, card, current

class CardCopyTestFlow(FlowSpec):
    """
    A flow that demonstrates the card copy functionality.
    """

    @card(type="blank")
    @step
    def start(self):
        """
        Create a card in the start step.
        """
        from metaflow.cards import Markdown
        current.card.append(Markdown("# Original Card"))
        current.card.append(Markdown("This card was created in the start step."))
        self.pathspec = current.pathspec
        self.next(self.copy_card)

    @card(type="blank")
    @step
    def copy_card(self):
        """
        Copy the card from the start step.
        """
        from metaflow.cards import Markdown

        # First, create a new card for this step
        current.card.append(Markdown("# Destination Card"))
        current.card.append(Markdown("This card was created in the copy_card step."))

        # Now, copy the card from the start step
        # Get the pathspec for the start step

        # Copy the card from the start step
        success = current.card.copy(self.pathspec)

        if success:
            current.card.append(Markdown("## Card Copy Success"))
            current.card.append(Markdown(f"Successfully copied card from {self.pathspec}"))
        else:
            current.card.append(Markdown("## Card Copy Failed"))
            current.card.append(Markdown(f"Failed to copy card from {self.pathspec}"))

        self.next(self.end)

    @step
    def end(self):
        """
        End the flow.
        """
        print("Flow completed successfully!")

if __name__ == "__main__":
    CardCopyTestFlow()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant