This creates an explicit class for symbolic tensors.
The Tensor base class remains shared between Eager and Graph tensors, but
becomes a pure interface type.
PiperOrigin-RevId: 529748789
This is to help support smaller model sizes for some
tflite models. Requires expanding the TF API to allow
specification of the type, `index_type`.
The change is backward-compatible.
Some changes in XLA were required to support the new
API.
PiperOrigin-RevId: 523499712
Imported from GitHub PR https://github.com/keras-team/keras/pull/17651
Implements the `CategoricalFocalCrossentropy()` loss based on the paper [Focal Loss for Dense Object Detection](https://arxiv.org/pdf/1708.02002.pdf) (Lin et al., 2018).
Feature request was made in #17583.
Copybara import of the project:
--
5696b5ab7dd401ca15b7e6ffba17ef05b1bb012a by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Add pure logic of CFCE
--
40e547feaf8a505e559fac6818780c985963f8cc by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Add support for ragged tensors
--
d3dd32f0a6fe7f5d90cf579677c905ebb2597328 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Make sure output sum equals 1
--
16adf8571a5f6415e3adb54415bf09d351fdf3af by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Raise shape mismatch / update tests
--
bc38e33153715846c5faaacb02f4e354a22b0561 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Add categorical_focal_loss tests
--
363baaf4c8c508de5a333b1e75a8cf6bbb9b6183 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Add documentation / minor fix.
--
c267fa0a118dc748707e50c36d33838a9f55776d by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Reformatting after focal loss implementation
--
3c33117f62a7580b4a17f394c797edf2f80b6972 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Fix linting.
--
3538622ace799cf1d9a5dd279af90098965665c3 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Fix docstring style.
--
6b4fa6b0dbba7351aa98fa2b39b74e82b85f5b54 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Update the docstrings.
--
49c03a2e1214cd7057dd5381c9602eebeaa4ff18 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Fix linting issues
--
f56033645287df77f6fd0c0741bb16b74090f0eb by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:
Address comments from code-review.
Merging this change closes#17651
PiperOrigin-RevId: 520482950
Imported from GitHub PR https://github.com/keras-team/keras/pull/17648
Hello,
here is the adapted `SpectralNormalization` from TF-Addons implementation.
Thanks.
Copybara import of the project:
--
0ae1ae70024b548fc2aee47c976ca4c30530157f by Martin Kubovcik <markub3327@gmail.com>:
+ SpectralNormalization
--
7f91062eea8d23f6407a2c3bc253e82e48a52e30 by Martin Kubovcik <markub3327@gmail.com>:
fixes
--
5fbe19ecadbdf69acb13f1b3aac3c411b1427c83 by Martin Kubovcik <markub3327@gmail.com>:
fix
--
f57b45aa5a635a3d75ec957e9ca3f7ce5984421c by Martin Kubovcik <markub3327@gmail.com>:
update
--
46269ea5fc5d404051c47a7eadcd42acd2a62ad6 by Martin Kubovcik <markub3327@gmail.com>:
update tests
Merging this change closes#17648
PiperOrigin-RevId: 520171696
Also open source the layout test files, and split the LayoutPropagation tests from layout test to speed up the test target a bit.
PiperOrigin-RevId: 518682489
1. All the optimizers and the base optimizer will take a new kwargs `mesh`, which will convert of the some behavior to DTensor, (eg DVariable for state variable, and some other reduction/aggregation logic.)
2. Delete all the implementation under dtensor/optimizers.py, but keep the tests to make sure the optimizers are covered for the dtensor setting.
3. Move the existing dtensor.optimizer export to the keras.optimizer, will keep it for one release cycle, and will delete them later.
PiperOrigin-RevId: 518367856
Previously issubclass(tuple[int, int], composite_tensor.CompositeTensor) raises a TypeError. This CL creates an internal _issubclass to only return True or False. So the original TypeError will not be raised. The Python tuple annotation was already correctly handled by the `type_annotations.is_generic_tuple` logic below.
PiperOrigin-RevId: 518309384
The current behavior is unchanged to avoid affecting backward compatibility but only added a new behavior to `tf.data.Dataset.zip` Python op for accepting a non-nested structure of datasets without doing the tuple.
PiperOrigin-RevId: 517472001
Imported from GitHub PR https://github.com/keras-team/keras/pull/17605
Add Lion optimizer to keras, using the experimental optimizer API.
Authors [implementation](http://github.com/google/automl/tree/master/lion) is based on legacy optimizer API.
Request for contribution was made [here](https://github.com/keras-team/keras/issues/17570)
Copybara import of the project:
--
89ba3e45094943931d577c9c21194aaec1764f97 by Malo <malo@milvue.com>:
Add Lion optimizer
--
6074929ccdfd2d4889a7c039e8b7163236c3533a by Malo <malo@milvue.com>:
Add missing docstring, remove checks
--
51041a5915c772a67314781c186639184993884a by Malo <malo@milvue.com>:
improve update step
--
0e0d77fd5f1544545980e9388bb0264751e01997 by Malo <malo@milvue.com>:
remove not needed stuff
--
2ede9c711ecdc731d644bc913944fe24d1b45c8c by Malo <malo@milvue.com>:
add lr and wd value recommendation
--
2a8e49939b37791f39b8f537bbe54e1f7187a376 by Malo <malo@milvue.com>:
allow beta_1 = 0
--
61224483219906ce4889cc9e94408ffa12d29b19 by Malo <malo@milvue.com>:
revert beta_1 = 0 and add correctness test
--
b368b93f88f4c9cedf0f0fe0c4a480d795f231ca by Malo <malo@milvue.com>:
add missing newline
--
4901592dd143f682c5ca43861dc5917977ee41dc by Malo <malo@milvue.com>:
revert back to register_keras + print value
--
fee5345c724ff53c056055a151c2f39b1445797e by Malo <malo@milvue.com>:
improve error message
Merging this change closes#17605
PiperOrigin-RevId: 516388327
Although they are still implementation details, this will allow user to do type checking as well as type annotation for their code.
PiperOrigin-RevId: 516295859
Uses local Variables via `experimental_enable_variable_lifting=False` to create short-lived Metric objects within each eval function. These metrics' variables are returned for aggregation on the chief.
PiperOrigin-RevId: 515634213
The current behavior is unchanged to avoid affecting backward compatibility but only added a new behavior to `tf.data.Dataset.zip` Python op for accepting a non-nested structure of datasets without doing the tuple.
PiperOrigin-RevId: 515440530
The current behavior is unchanged to avoid affecting backward compatibility but only added a new behavior to `tf.data.Dataset.zip` Python op for accepting a non-nested structure of datasets without doing the tuple.
PiperOrigin-RevId: 515389129
This is because LMDB has vulnerabilities and there are very few users of this feature, so it does not make sense to include it in TF.
PiperOrigin-RevId: 514551603
dtensor.run_on() tends to cause confusion since it indicates override semantics (force the functions and ops in the context to run on the supplied mesh), even though the implementation only provides fallback semantics.
PiperOrigin-RevId: 513949632
Becuase the automation that updates the release notes in master after branch cut for release happens has been destroyed and the step has not been done manually in time, we have commits such as 9fbf113704# and ba1372a41e that write the wrong contents to the release notes.
PiperOrigin-RevId: 507025073
Type float16 and float64 input/output for TensorFlow 'cast' operator is used in some Federated Learning models, thus adding these type supports to TFLite 'cast' op can make these operators converted to TFLite build-in ops instead of flex ops.
PiperOrigin-RevId: 506997479
Note: there are enough saving-related utils that we should centralize them in their own namespace instead of overloading `utils`. Besides the `models` namespace is likely to be increasingly used for actual model instances (e.g. the SAM optimizer model...)
PiperOrigin-RevId: 505214178
Type float16 and float64 input/output for TensorFlow 'cast' operator is used in some Federated Learning models, thus adding these type supports to TFLite 'cast' op can make these operators converted to TFLite build-in ops instead of flex ops.
PiperOrigin-RevId: 502669256
Type float16 and float64 input/output for TensorFlow 'cast' operator is used in some Federated Learning models, thus adding these type supports to TFLite 'cast' op can make these operators converted to TFLite build-in ops instead of flex ops.
PiperOrigin-RevId: 502638398
496953709 by A. Unique TensorFlower<gardener@tensorflow.org>:
496952678 by A. Unique TensorFlower<gardener@tensorflow.org>:
Fix iOS nightly release build. Add profiler.h in TensorFlowLiteC framework headers.
--
496952616 by A. Unique TensorFlower<gardener@tensorflow.org>:
Convert _placeholder_value into a public API.
--
496949861 by A. Unique TensorFlower<gardener@tensorflow.org>:
[XLA] Make HloModuleConfig own the string keys in `analysis_allowance_map_`
This fixes a use-after-free bug when deserializing an HloModuleConfig:
f1251be098/tensorflow/compiler/xla/service/hlo_module_config.cc (L304-L306)
Without this change, the keys of `analysis_allowance_map_` have the
same lifetime as the input proto that's being deserialized, which is
probably very inconvenient semantics for the caller. In practice there
are not many keys and they're short, so I don't think the extra string
copy will have a noticeable performance impact.
--
496949804 by A. Unique TensorFlower<gardener@tensorflow.org>:
Update the JAX's docker image to base it on the new image that TF has.
--
496947227 by A. Unique TensorFlower<gardener@tensorflow.org>:
Remove unused imports.
--
496944423 by A. Unique TensorFlower<gardener@tensorflow.org>:
Bypass nvprune if compiling with CUDA Clang. Retry
--
496941078 by A. Unique TensorFlower<gardener@tensorflow.org>:
496940772 by A. Unique TensorFlower<gardener@tensorflow.org>:
Add `ParseFromString` method to `OpSharding` Python bindings.
--
496940632 by A. Unique TensorFlower<gardener@tensorflow.org>:
Remove PAT from Scorecards workflow
This should make the workflow work again. Will test after this lands.
Signed-off-by: Mihai Maruseac <mihaimaruseac@google.com>
--
496939937 by A. Unique TensorFlower<gardener@tensorflow.org>:
Automated visibility attribute cleanup.
--
496939490 by A. Unique TensorFlower<gardener@tensorflow.org>:
Remove all PTX except for the specified one.
--
496931612 by A. Unique TensorFlower<gardener@tensorflow.org>:
Integrate StableHLO at openxla/stablehlo@e8c1c04
--
496919498 by A. Unique TensorFlower<gardener@tensorflow.org>:
[JITRT] Add a regression_test for broadcasting.
This is a reduced version of broadcasting_2, which is much easier to
read/debug.
--
496918085 by A. Unique TensorFlower<gardener@tensorflow.org>:
Add RBE to linux builds to improve test times.
--
496914744 by A. Unique TensorFlower<gardener@tensorflow.org>:
Add serialization support to FeatureSpace.
--
496911817 by A. Unique TensorFlower<gardener@tensorflow.org>:
[IFRT] Remove BUILD file tests for IFRT, which is always enabled now.
--
496911684 by A. Unique TensorFlower<gardener@tensorflow.org>:
[GmlSt] Implement `reifyResultShapes` for `gml_st.materialize`.
--
496906503 by A. Unique TensorFlower<gardener@tensorflow.org>:
PR #58850: Update compat.py
Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/58850
Fixed the broken link of tf.compat.forward_compatible.
Copybara import of the project:
--
458964893973f6aa7e1d59ab852587918f5a2ef4 by Tirumalesh <111861663+tiruk007@users.noreply.github.com>:
Update compat.py
Fixed the broken link of (tf.compat.forward_compatible)[https://www.tensorflow.org/api_docs/python/tf/compat/forward_compatible]
Merging this change closes#58850
--
496904759 by A. Unique TensorFlower<gardener@tensorflow.org>:
496895256 by A. Unique TensorFlower<gardener@tensorflow.org>:
[DelegatePerformance] Split the targets out into subpackages.
--
496893002 by A. Unique TensorFlower<gardener@tensorflow.org>:
Remove unused `tf-jitrt-symbolic-shape-optimization` pass
--
496887677 by A. Unique TensorFlower<gardener@tensorflow.org>:
[GmlSt] Tile map and fill ops again in a peeled loop for scalarization.
The perfectly-tiled part of the loop remains unchanged and will be vectorized. Ops in the peeled loop should be scalarized later.
--
496885897 by A. Unique TensorFlower<gardener@tensorflow.org>:
[MLIR:XLA] Move shape.bcast simplification into the MHLO's shape optimization pass
Also, remove the old shape optimization pass from the pipeline.
--
496880934 by A. Unique TensorFlower<gardener@tensorflow.org>:
[DelegatePerformance] Handle failures from parsing latency results.
--
496878266 by A. Unique TensorFlower<gardener@tensorflow.org>:
Internal fixes.
--
496866713 by A. Unique TensorFlower<gardener@tensorflow.org>:
Add failing tests for XlaCallModule.
The newly added tests are failing at the moment and are disabled.
Added here to help debugging.
--
496864860 by A. Unique TensorFlower<gardener@tensorflow.org>:
[XLA:GPU] [NFC] Remove unused function
--
496859249 by A. Unique TensorFlower<gardener@tensorflow.org>:
Cleaning up BUILD files to remove "loose" headers.
--
PiperOrigin-RevId: 496953709
Imported from GitHub PR https://github.com/keras-team/keras/pull/17145
Fixes missing part of issue #15425 where `model.summary(show_trainable=True)` was implemented but `plot_model(model, show_trainable=True)` wasn't.
Also fixes a failing test case when having pydot & graphviz installed.
Copybara import of the project:
--
56de08b3048dac6398e6347eba3699fa560a0ba1 by Mateo Fidabel <mateofidabel@fpuna.edu.py>:
Added show_trainable to plot_model()
--
c6f8a64747b2c0812f7616eec36c4c91260f83c5 by Mateo Fidabel <mateofidabel@fpuna.edu.py>:
Fixed failing test case on vis_utils_test.py
Merging this change closes#17145
PiperOrigin-RevId: 494280644
Masked losses with the default "auto" reduction were giving outputs that are
inconsistent with what you would get from a ragged input. Masked and Ragged are two different representations of the same thing (when it can be represented as ragged). These should match.
The (input_type='masked', reduction='auto') case fails (doesn't match the ragged case) before this change.
The existing tests, where I'm changing the expected values are because I believe the old values are incorrect.
PiperOrigin-RevId: 493003876
Imported from GitHub PR https://github.com/keras-team/keras/pull/17291
@fchollet
Please see #17251.
Copybara import of the project:
--
356eaa8a7b035dcac2a565f9dde38201334f1c0c by Aditya Kane <64411306+AdityaKane2001@users.noreply.github.com>:
Added identity layer
--
b8240ece60fced29c0e47970219c064bed18ae83 by Aditya Kane <adityakane1@gmail.com>:
added identity to core import
Merging this change closes#17291
PiperOrigin-RevId: 492867838
Also, define XlaOpKernel for this op leveraging the existing implementation but propagate indices_are_sorted to HLO Scatter op.
Having the num_segments as an input makes the output type bounded and can be supported in XLA.
PiperOrigin-RevId: 489096541
`sparse_reorder` now preserves the static rank and statically known dimensions of the tensor.
Previously, `sparse_reorder` would only keep the static rank and dimensions if the static shape was fully defined, and would otherwise make the shape fully dynamic. There is however value in keeping a static rank and know static dimensions even if the shape is not fully defined. One common use case is when the batch size is not known but other dimensions are fully defined.
PiperOrigin-RevId: 479108317
Currently `experimental_enable_variable_lifting=False` only works on non-XLA devices (e.g. under `@tf.function(jit_compile=False)`).
PiperOrigin-RevId: 477033035
By doing so, we will be able to nest ResourceVariables in ExtensionType/CompositeTensor. It will also clear our way to return ResourceVariables from tf.function and pass variable through control flow.
Note, with this CL, tf.nest with expand_composites=True will not expand resource variables into dt_resource tensors. That will be done in a following CL to reduce the chance of being rolled back for this CL.
`CompositeTensor` is added to baseclasses of `tf.experimental.dtensor.DVariable` because it is a subclass of ResourceVariable.
PiperOrigin-RevId: 476416307
If provided, tf.data service will use the provided ID for the dataset.
If the dataset ID already exists, no new dataset will be registered.
This is useful if multiple training jobs need to use the same dataset
for training. In this case, users should call `register_dataset` with
the same `dataset_id`.
PiperOrigin-RevId: 462690057
Imported from GitHub PR https://github.com/keras-team/keras/pull/16712
Properly fixes#6118 and #5911.
#### Summary
* Add the `ignore_index: Optional[int]` parameter to the following functions/constructors:
- `backend.sparse_categorical_crossentropy`
- `lossses.sparse_categorical_crossentropy`
- `metrics.SparseCategoricalCrossentropy`
- `metrics._IoUBase`
- `metrics.IoU`
- `metrics.MeanIoU`
- `metrics.OneHotIoU`
- `metrics.OneHotMeanIoU`
* Add `sparse_labels: bool` and `sparse_preds: bool` parameters in `_IoUBase`, `IoU`, `MeanIoU` metric classes.
* Add `sparse_preds:bool` to the `OneHotIoU` and `OneHotMeanIoU` metric classes.
* Refactor: A replicated code section shared among `backend.categorical_crossentropy`, `backend.sparse_categorical_crossentropy`, and `backend.binary_crossentropy` into a single function named `_get_logits`.
#### Goals
1. **ignore_index**: In segmentation problems, some pixels in segmentation maps might not represent valid categorical labels. Examples:
- object boundaries are marked with void category, as the annotators disagree on which label to attribute
- small maps are padded with the *void* class to conform with the sizes of larger ones after `Dataset#padded_batch`
- specific objects out of the context of the problem, such as the hood of a car being captured by a static camera
- pseudo-labels (originated from weakly supervised strategies) might contain pixels/regions where label is uncertain
It's common to attribute the label `-1` or `255` and ignore these pixels during training. This PR implements this feature by masking the target and the output signals, only computing the metrics over the valid pixels. Moreover, it mirrors PyTorch's [CrossEntropyLoss(ignore_index=-100)](https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html).
2. **sparse_preds**: `IoU` and `MeanIoU` assumes both `target` and `output` are sparse signals, where categories are represented as natural integers. Conversely, `OneHotIoU` and `OneHotMeanIoU` assume both are probability distribution vectors. This is far from what I believe to be the most obvious case: sparse segmentation labels and dense output vectors:
```py
>>> classes = 20
>>> model = Sequential([
>>> ResNet50V2(input_shape=[512, 512, 3], include_top=False, pooling=None, weights=None),
>>> Conv2D(classes, kernel_size=1, activation='softmax', name='predictions')
>>> ])
>>> print(model.output.shape)
(None, 16, 16, 20)
```
So now IoU can be easily used as this:
```py
model.compile(opt='sgd', loss='sparse_categorical_crossentropy', metrics=[
MeanIoU(classes, sparse_preds=False, ignore_index=-1)
])
```
#### Limitations
Currently, `backend.sparse_categorical_crossentropy` only reduces the dimension containing the logits, and the result is reshaped into the original output shape (except for the last axis) if the information is available.
However, when a pixel is not valid, its associated cross-entropy value is not available and reshape cannot occur without creating a ragged tensor. Therefore, when `ignore_index is not None` (and only then), I opted to sum all cross-entropy values over the axes `range(1, output_rank-1)` and divide by the number of valid pixels (similar to what pytorch does). In this case, the output tensor will have `shape=[output_shape[0]]=[batch_size]`.
An alternative would be to return a flatten array containing only valid entries, though the batch information would be lost and the user would have difficulties if they had per-sample operations being applied to these loss values.
Copybara import of the project:
--
b7f02816b5320855ae528971766fdcaad7134a9b by lucasdavid <lucasolivdavid@gmail.com>:
Add ignore_index crossentropy and IoU
--
1589a843bac4390c8377db05cbd6ae650b6210cc by lucasdavid <lucasolivdavid@gmail.com>:
Remove duplicate convert_to_tensor
--
70f7fb6789e1a7e030737a46847b24b892965e4e by lucasdavid <lucasolivdavid@gmail.com>:
Rename ignore_index to ignore_label, update docs
--
db9f76ac8d1945630061582b03381939349bb59a by lucasdavid <lucasolivdavid@gmail.com>:
Implement masked loss reduction
--
4f1308112f4188c4e14fdf3a59af8fe5f30db61f by lucasdavid <lucasolivdavid@gmail.com>:
Update docs
Merging this change closes#16712
PiperOrigin-RevId: 461661376
This is a first go at adding Keras masking support and causal support to the `MultiHeadAttention` layer.
See the discussion in [#16248](https://github.com/keras-team/keras/issues/16248).
Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/16619
Copybara import of the project:
- c0293ded9abe8ac7719cceb0095fa9dff807d2fe Add support for Keras masking and causal masking by Aurélien Geron <ageron@users.noreply.github.com>
- 015625fb981212a97c282b71a0479b6e7cada6b3 Replace causal in init with use_causal_mask in call by Aurélien Geron <ageron@users.noreply.github.com>
- ebf46bf42166a36068017d12d999d0ecd6e55d69 Reformat code using shell/format.sh by Aurélien Geron <ageron@users.noreply.github.com>
- 9ec97ba141354c8b34b7735942ffb207766b2d96 Fix docstring indentation and missing line breaks by Aurélien Geron <ageron@users.noreply.github.com>
- b00b4b462d74d3f3a387a07550945c1d19e6ebe2 Merge branch 'master' into mha_automask by Aurélien Geron <ageron@users.noreply.github.com>
- 76055673c562571c088f80184c70034221a6ee7e Add defensive casting to bool for implicit and explicit m... by Aurélien Geron <ageron@users.noreply.github.com>
- 1f724936ce4753fd83d4cdb7bec03b49b3def98f Merge 76055673c562571c088f80184c70034221a6ee7e into e1d39... by Aurélien Geron <ageron@users.noreply.github.com>
PiperOrigin-RevId: 460320823
Also remove testing of causal masks from `layer_correctness` since not needed and changing arguments in call doesn't fit easily into this test fixture.
PiperOrigin-RevId: 459791640
Update TFLite build rules to use Flatbuffer v2.0.5
Also following changes are made:
- Updated schema_generated.h for 2.0.5.
- Fix a regression in flatbuffer_export.cc
- Update tensor comparison logic in quantize_model_test.cc
PiperOrigin-RevId: 454483837
A new argument experimental_device_ordinal is added to LogicalDeviceConfiguration,
and plumbed to gpu_device.cc. The logical devices created will be ordered by
(device_ordinal, location in the flattened logical device configuration list).
If device_ordinal is 0 (default), then we get the current behavior where all logical devices of the same physical devices receive nearby tf device ids.
If device_ordinal is incremental per config-group for a physical device, then we can round-robin the logical devices.
This works around the limitation where logical to physical association cannot be changed after established during the process life time. The error is raised from TfToPlatformDeviceIdMap::Insert, which is a per process singleton, but there may be additional constraints.
DTensor 2GPU unit tests (not OSS yet) trigger this, and the tests pass after this fix.
PiperOrigin-RevId: 454191314
There will be a behavior change after this cl.
1. Unseeded initializer will always generate same value after creation.
2. Unseeded initializer will raise a warning if it is reused (called) multiple times. This is to avoid reuse the instance for multiple variables, which could generate same value when shapes are the same.
3. Seeded initializer will always generate same value after creation, instead of determinist sequence.
PiperOrigin-RevId: 453967472