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

[Data] Allow automatic handling of string features as byte features during TFRecord serialization #37995

Merged
merged 5 commits into from
Aug 2, 2023

Conversation

EdwardCuiPeacock
Copy link
Contributor

@EdwardCuiPeacock EdwardCuiPeacock commented Aug 1, 2023

[Sorry, previous PR was kind of messed up...]

Why are these changes needed?

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).

Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

…erialization

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
@amogkam
Copy link
Contributor

amogkam commented Aug 1, 2023

Thanks for the contribution @EdwardCuiPeacock! Do you think you can add a small test for this in test_tfrecords.py? We can add a case for string in test_read_tfrecords

Also cc @scottjlee for review

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
@EdwardCuiPeacock
Copy link
Contributor Author

Hi, @amogkam . I added the new unit tests. To install the test_requirement.txt though, I had to change numba from version 0.56.4 to 0.57.1 temporarily, since 0.56.4 does not have a Python 3.11 wheel built (maybe we should upgrade that at some point). But all tests in test_tfrecords.py should be passing now.

Copy link
Contributor

@scottjlee scottjlee left a comment

Choose a reason for hiding this comment

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

Thanks for adding this feature!

@EdwardCuiPeacock EdwardCuiPeacock changed the title Allow automatic handling of string features as byte features during TFRecord serialization [Data] Allow automatic handling of string features as byte features during TFRecord serialization Aug 2, 2023
@amogkam amogkam merged commit 32212dc into ray-project:master Aug 2, 2023
57 of 63 checks passed
@amogkam
Copy link
Contributor

amogkam commented Aug 2, 2023

Thanks for the contribution @EdwardCuiPeacock! It's been merged.

justinvyu pushed a commit to justinvyu/ray that referenced this pull request Aug 2, 2023
…uring TFRecord serialization (ray-project#37995)

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).
Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

---------

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
NripeshN pushed a commit to NripeshN/ray that referenced this pull request Aug 15, 2023
…uring TFRecord serialization (ray-project#37995)

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).
Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

---------

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: NripeshN <nn2012@hw.ac.uk>
harborn pushed a commit to harborn/ray that referenced this pull request Aug 17, 2023
…uring TFRecord serialization (ray-project#37995)

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).
Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

---------

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: harborn <gangsheng.wu@intel.com>
harborn pushed a commit to harborn/ray that referenced this pull request Aug 17, 2023
…uring TFRecord serialization (ray-project#37995)

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).
Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

---------

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…uring TFRecord serialization (ray-project#37995)

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).
Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

---------

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
…uring TFRecord serialization (ray-project#37995)

I am attempting to use ray.data.write_tfrecords to convert my features into TFRecords. Since some of my features are string features, the following error is thrown:

ValueError: Value is of type string, which we cannot convert to a supported tf.train.Feature storage type (bytes, float, or int).
Naturally, TFRecords serializes string features as bytes feature automatically (as typically done in Tensorflow and Tensorflow-extended (TFX); see for example: https://github.com/tensorflow/tfx/blob/fd070288ffa5dcb28204810d2bed261c7e1df201/tfx/components/example_gen/csv_example_gen/executor.py#L67). Making the TFRecord writer automatically treat strings as bytes would help serialize string features correctly, avoiding the hassle of creating additional map functions to convert string features into bytes.

When reading TFRecords, however, we should still keep the bytes features as bytes, as the program does not necessarily know a byte object represents a string. In this example provided by Tensorflow, tensors are serialized into bytes and stored in tfrecords, using tf.io.serialize_tensor.

---------

Signed-off-by: EdwardCuiPeacock <Edward.Cui@nbcuni.com>
Signed-off-by: Victor <vctr.y.m@example.com>
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

3 participants