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

artifact link #1363

Merged
merged 24 commits into from
Nov 27, 2024
Merged

artifact link #1363

merged 24 commits into from
Nov 27, 2024

Conversation

dafnapension
Copy link
Collaborator

@dafnapension dafnapension commented Nov 18, 2024

closes: #1341

@elronbandel
Copy link
Member

elronbandel commented Nov 18, 2024

It looks good, just not sure, how to support the overwrite args.
Not sure how we could pass the arguments from the old artifact to the new one.
Lets say someone uses metrics.accurcay[lower_case=True] and metrics.accuracy points to its new name metrics.exact_match how can we pass the arguments [lower_case=True] to the new artifact ? (effectively resulting in metrics.exact_match[lower_case=True]) @yoavkatz @dafnapension what do you think?

@dafnapension
Copy link
Collaborator Author

Hi @elronbandel ,
As it is now, the new_artifact is a whole: an instantiated artifact. It is returned as is. Potentially, it does not have at all the fields specified in the overwrites of the original artifact referenced.
I think that a clear documentation can cover this issue.. :-)

@elronbandel
Copy link
Member

The issue is old code with references to deprecated catalog names.
If someone has metrics.accurcay[lower_case=True] and we referred metrics.accurcay->metrics.exact_match his code wont work as before due to the arguments overwrite not being passed: [lower_case=True]

@@ -412,6 +412,18 @@ def get_raw(obj):
return shallow_copy(obj)


class ArtifactLink(Artifact):
new_artifact: Artifact
is_self_deprecated: bool
Copy link
Member

Choose a reason for hiding this comment

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

In think deprecation and linking are distinct properties.

We can deprecate something without having a new link to it. So every artifact should have a deprecated field.

@dafnapension
Copy link
Collaborator Author

@yoavkatz , @elronbandel , I tried to address both your valuable comments. Please see.

@dafnapension dafnapension force-pushed the artifact_link branch 2 times, most recently from 306bc37 to 09b6611 Compare November 19, 2024 08:32
@@ -138,6 +139,14 @@ class Artifact(Dataclass):
)
__id__: str = InternalField(default=None, required=False, also_positional=False)

__is_deprecated__: bool = NonPositionalField(
Copy link
Member

Choose a reason for hiding this comment

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

We should add description of the features to the

https://www.unitxt.ai/en/latest/docs/saving_and_loading_from_catalog.html

Copy link
Collaborator Author

@dafnapension dafnapension Nov 19, 2024

Choose a reason for hiding this comment

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

@yoavkatz , I removed field __is_deprecated__ altogether, since we already have the @deprecation decorator from deprecation_utils. Decorating class RenameFields, for example.
Yet, I added a test that combines deprecation with links.
And moved the link to the other Artifact to class ArtifactLink as you suggested.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks Dafna.
There is a difference between deprecating a class and deprecating an instance.
For example, I can have a card saved as "card.sst" and at some point I want to call it "card.sst2".
I want to make the change be backward compatible, so "cards.sst" becomes a deprecated with warning. It is also replaced with ArtficactLink to "card.sst2".

Note that "Card" class was never deprecated

I also think a link should always be to acatalog entry and not an object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, Yoav,
I hope I got it better now.. The easy thing was only allowing a link to be expressed as a catalog-entry id.
What I was not sure about is what to do with the 'deprecated bit' that is now back into Artifact's fields.
For now, I implemented the bit as a string | None. I.e.: if None then not deprecated, and if string - is deprecated. In such a case, a warning message, being that string, is logged as a Warn, when the artifact's prepare(self) is run. That's the only sanction..

src/unitxt/artifact.py Outdated Show resolved Hide resolved
@dafnapension dafnapension force-pushed the artifact_link branch 7 times, most recently from 22781e2 to 8a2cfb9 Compare November 20, 2024 14:12
@dafnapension dafnapension force-pushed the artifact_link branch 3 times, most recently from c3931a7 to 33fc54a Compare November 21, 2024 12:16
return Artifact.load(artifact_rep), None
artifact_to_return = Artifact.load(artifact_rep)
if isinstance(artifact_rep, ArtifactLink):
artifact_to_return = artifact_to_return.artifact_linked_to
Copy link
Member

Choose a reason for hiding this comment

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

Same here. The fetch_artificat should return the artificat, not the name of the artifact we link to.

Copy link
Collaborator Author

@dafnapension dafnapension Nov 21, 2024

Choose a reason for hiding this comment

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

Hi @yoavkatz , and thanks again for your neat idea about the dedicated load of ArtifactLink. I just expanded it to also allow link to link to link (imagine that.. with the overwrites that @elronbandel emphasized floating all the way over the links in the middle, until they can be applied on the final, non-link Artifact that can digest them - only it is expected to have these keys that show in the overwrites).

And thanks for your new comment. I see what you mean, and hope I put it right now, backed with many tests. Please see, and suggest any test you see fit.

Copy link
Collaborator Author

@dafnapension dafnapension Nov 21, 2024

Choose a reason for hiding this comment

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

Hi @yoavkatz , I also added the requested documentation:

image

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! I've added some followup feedback.

src/unitxt/artifact.py Outdated Show resolved Hide resolved
@dafnapension dafnapension force-pushed the artifact_link branch 2 times, most recently from 4676b32 to 117080d Compare November 22, 2024 22:45
dafnapension and others added 14 commits November 25, 2024 15:05
Signed-off-by: dafnapension <[email protected]>
…y to the final target artifact, which is the only one that can digest them.

Signed-off-by: dafnapension <[email protected]>
Signed-off-by: dafnapension <[email protected]>
Added example of links in catalog.

Signed-off-by: Yoav Katz <[email protected]>
Signed-off-by: Yoav Katz <[email protected]>
Signed-off-by: dafnapension <[email protected]>
Signed-off-by: dafnapension <[email protected]>
@dafnapension
Copy link
Collaborator Author

dafnapension commented Nov 25, 2024

Hi @yoavkatz , I fought the red color, but I think I won. please let me know if this is anywhere near what you had in mind. The deprecation msg is printed at the top of the artifact documentation.
I am not sure about what you said re. artifact.__description__ . these are always printed at the top. E.g.:
https://www.unitxt.ai/en/latest/catalog/catalog.cards.almost_evil.html

image

which also shows on the dir level:

image

@yoavkatz
Copy link
Member

yoavkatz commented Nov 25, 2024

Thanks Dafna.

Looking good. Two suggestions:

  1. "Deprecation message:" as a prefix to the deprecation message.
  2. Remove the deprecation message from the displayed yaml (as it is redundant)

@dafnapension
Copy link
Collaborator Author

Hi @yoavkatz , how's this: ?

image

Please point for me where you see the __description__ or __tags__ field in the yaml. I may be looking another way.. Are you referring to the Explanations about that show below the yaml, which bring the docstrings of the classes mentioned in the yaml (and were recently made by @elronbandel into clickable links)?

@yoavkatz yoavkatz enabled auto-merge (squash) November 27, 2024 10:16
@yoavkatz
Copy link
Member

Thanks for the great work. Once it finishes testing , I'll merge it.

@yoavkatz yoavkatz merged commit f203f41 into main Nov 27, 2024
16 checks passed
@yoavkatz yoavkatz deleted the artifact_link branch November 27, 2024 10:24
ShirApp pushed a commit that referenced this pull request Nov 28, 2024
* artifact link

Signed-off-by: dafnapension <[email protected]>

* riding on recursive_load to allow overwrites with links

Signed-off-by: dafnapension <[email protected]>

* prepare for replacement sitting in a different catalog

Signed-off-by: dafnapension <[email protected]>

* removed __is_deprecated__ and moved the link to a dedicated class ArtifactLink

Signed-off-by: dafnapension <[email protected]>

* link only via catalog-entry id, deprecation msg for individual artifacts, not only classes

Signed-off-by: dafnapension <[email protected]>

* added a dedicated load() for ArtifactLink, per yoav's suggestion

Signed-off-by: dafnapension <[email protected]>

* a cleaner separation

Signed-off-by: dafnapension <[email protected]>

* allow link to link to link.. with the overwriting floating all the way to the final target artifact, which is the only one that can digest them.

Signed-off-by: dafnapension <[email protected]>

* test ultimate instantiation of ArtifactLink to an Actual Artifact - the target of the link

Signed-off-by: dafnapension <[email protected]>

* artifact_linked_to is a required field

Signed-off-by: dafnapension <[email protected]>

* added documentation to Tutorials

Signed-off-by: dafnapension <[email protected]>

* reworded documentation some

Signed-off-by: dafnapension <[email protected]>

* check validity of artifact_linked_to before fetching by it

Signed-off-by: dafnapension <[email protected]>

* Added example of deprecation of an asset

Signed-off-by: Yoav Katz <[email protected]>

* Made link a position field in ArtificatLink.

Added example of links in catalog.

Signed-off-by: Yoav Katz <[email protected]>

* Fixed typo.

Signed-off-by: Yoav Katz <[email protected]>

* rephrased documentation per Yoav's suggestions, and added a test

Signed-off-by: dafnapension <[email protected]>

* made explanation rst-friendly

Signed-off-by: dafnapension <[email protected]>

* some suggested changes I missed before

Signed-off-by: dafnapension <[email protected]>

* red deprecation

Signed-off-by: dafnapension <[email protected]>

* show deprecation message only at the top of the documentation, not inside the yanl

Signed-off-by: dafnapension <[email protected]>

* also leave the existing removal of __tags__ and __description__

Signed-off-by: dafnapension <[email protected]>

* deprecated regular asset

Signed-off-by: dafnapension <[email protected]>

---------

Signed-off-by: dafnapension <[email protected]>
Signed-off-by: Yoav Katz <[email protected]>
Co-authored-by: Yoav Katz <[email protected]>
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.

Need a way to rename and deprecate artifacts
3 participants