Skip to content

Commit

Permalink
Create Tensorflow public documentation for the new type promotion in …
Browse files Browse the repository at this point in the history
…TF-NumPy.

See the [design doc](https://docs.google.com/document/d/17TPlPVSRL_JA9nZ53w4ztAGuG2C-Hyd3-WIcvw0QNMQ/edit?usp=sharing&resourcekey=0-92wfQRXLZqJQZTUnDy47oA) here for more details about the new type promotion.

PiperOrigin-RevId: 555729892
  • Loading branch information
tensorflower-gardener authored and copybara-github committed Aug 11, 2023
1 parent 9639e1e commit 1637c45
Show file tree
Hide file tree
Showing 5 changed files with 1,162 additions and 4 deletions.
3 changes: 3 additions & 0 deletions site/en/guide/_toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ toc:
- title: "NumPy API"
status: experimental
path: /guide/tf_numpy
- title: "NumPy API Type Promotion"
status: nightly
path: /guide/tf_numpy_type_promotion
- title: "DTensor concepts"
path: /guide/dtensor_overview
status: experimental
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions site/en/guide/tf_numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"\n",
"An instance of `tf.experimental.numpy.ndarray`, called **ND Array**, represents a multidimensional dense array of a given `dtype` placed on a certain device. It is an alias to `tf.Tensor`. Check out the ND array class for useful methods like `ndarray.T`, `ndarray.reshape`, `ndarray.ravel` and others.\n",
"\n",
"First create an ND array object, and then invoke different methods. "
"First create an ND array object, and then invoke different methods."
]
},
{
Expand Down Expand Up @@ -170,11 +170,28 @@
{
"cell_type": "markdown",
"metadata": {
"id": "Mub8-dvJMUr4"
"id": "-BOY8CGRKEhE"
},
"source": [
"### Type promotion\n",
"\n",
"There are 4 options for type promotion in TensorFlow.\n",
"\n",
"- By default, TensorFlow raises errors instead of promoting types for mixed type operations.\n",
"- Running `tf.numpy.experimental_enable_numpy_behavior()` switches TensorFlow to use `NumPy` type promotion rules (described below).\n",
"- After TensorFlow 2.15, there are two new options (refer to [TF NumPy Type Promotion](tf_numpy_type_promotion.ipynb) for details):\n",
" - `tf.numpy.experimental_enable_numpy_behavior(dtype_conversion_mode=\"all\")` uses Jax type promotion rules.\n",
" - `tf.numpy.experimental_enable_numpy_behavior(dtype_conversion_mode=\"safe\")` uses Jax type promotion rules, but disallows certain unsafe promotions."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "SXskSHrX5J45"
},
"source": [
"#### NumPy Type Promotion\n",
"\n",
"TensorFlow NumPy APIs have well-defined semantics for converting literals to ND array, as well as for performing type promotion on ND array inputs. Please see [`np.result_type`](https://numpy.org/doc/1.16/reference/generated/numpy.result_type.html) for more details."
]
},
Expand All @@ -200,7 +217,7 @@
" (tnp.int32, tnp.int64, tnp.float32, tnp.float64)]\n",
"for i, v1 in enumerate(values):\n",
" for v2 in values[i + 1:]:\n",
" print(\"%s + %s => %s\" % \n",
" print(\"%s + %s => %s\" %\n",
" (v1.dtype.name, v2.dtype.name, (v1 + v2).dtype.name))"
]
},
Expand Down Expand Up @@ -932,8 +949,8 @@
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [],
"name": "tf_numpy.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
Expand Down
Loading

0 comments on commit 1637c45

Please sign in to comment.