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

Exclude HF token from serialization #1129

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

Conversation

sysradium
Copy link

@sysradium sysradium commented Mar 6, 2025

Currently only api_key is being proactively excluded from dumps on any object.
However, HF related objects, like TransformersLLM, define token as a SecretStr: https://github.com/argilla-io/distilabel/blob/main/src/distilabel/models/llms/huggingface/transformers.py#L110

That leads either to a failure to save:

generation_model_1.save()
*** TypeError: Type is not JSON serializable: SecretStr

Or a successful save:

generation_model_1.save(format="yaml")

That would produce a YAML file with:

token: !!python/object:pydantic.types.SecretStr
  _secret_value: hf_lkjreglkn290Elnwef111j

That is unusable. And leads to a failure like:

distiset = pipeline.run()             
distiset.save_to_disk(distiset_path="dataset") 

ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object:pydantic.types.SecretStr'
  in "<unicode string>", line 105, column 16:
            token: !!python/object:pydantic.types.S ...

A comment says like it should have been filtered automatically out since it is a SecretStr, however, nowhere can I use an encoder defined to do this.

So I went with the smallest change, just including the token into the exclusion list.

@sysradium sysradium marked this pull request as ready for review March 6, 2025 22:21
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.

1 participant