Skip to content

Commit 1637c45

Browse files
Create Tensorflow public documentation for the new type promotion in 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
1 parent 9639e1e commit 1637c45

File tree

5 files changed

+1162
-4
lines changed

5 files changed

+1162
-4
lines changed

site/en/guide/_toc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ toc:
5555
- title: "NumPy API"
5656
status: experimental
5757
path: /guide/tf_numpy
58+
- title: "NumPy API Type Promotion"
59+
status: nightly
60+
path: /guide/tf_numpy_type_promotion
5861
- title: "DTensor concepts"
5962
path: /guide/dtensor_overview
6063
status: experimental
84.5 KB
Loading
281 KB
Loading

site/en/guide/tf_numpy.ipynb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"\n",
143143
"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",
144144
"\n",
145-
"First create an ND array object, and then invoke different methods. "
145+
"First create an ND array object, and then invoke different methods."
146146
]
147147
},
148148
{
@@ -170,11 +170,28 @@
170170
{
171171
"cell_type": "markdown",
172172
"metadata": {
173-
"id": "Mub8-dvJMUr4"
173+
"id": "-BOY8CGRKEhE"
174174
},
175175
"source": [
176176
"### Type promotion\n",
177177
"\n",
178+
"There are 4 options for type promotion in TensorFlow.\n",
179+
"\n",
180+
"- By default, TensorFlow raises errors instead of promoting types for mixed type operations.\n",
181+
"- Running `tf.numpy.experimental_enable_numpy_behavior()` switches TensorFlow to use `NumPy` type promotion rules (described below).\n",
182+
"- After TensorFlow 2.15, there are two new options (refer to [TF NumPy Type Promotion](tf_numpy_type_promotion.ipynb) for details):\n",
183+
" - `tf.numpy.experimental_enable_numpy_behavior(dtype_conversion_mode=\"all\")` uses Jax type promotion rules.\n",
184+
" - `tf.numpy.experimental_enable_numpy_behavior(dtype_conversion_mode=\"safe\")` uses Jax type promotion rules, but disallows certain unsafe promotions."
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {
190+
"id": "SXskSHrX5J45"
191+
},
192+
"source": [
193+
"#### NumPy Type Promotion\n",
194+
"\n",
178195
"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."
179196
]
180197
},
@@ -200,7 +217,7 @@
200217
" (tnp.int32, tnp.int64, tnp.float32, tnp.float64)]\n",
201218
"for i, v1 in enumerate(values):\n",
202219
" for v2 in values[i + 1:]:\n",
203-
" print(\"%s + %s => %s\" % \n",
220+
" print(\"%s + %s => %s\" %\n",
204221
" (v1.dtype.name, v2.dtype.name, (v1 + v2).dtype.name))"
205222
]
206223
},
@@ -932,8 +949,8 @@
932949
"metadata": {
933950
"accelerator": "GPU",
934951
"colab": {
935-
"collapsed_sections": [],
936952
"name": "tf_numpy.ipynb",
953+
"provenance": [],
937954
"toc_visible": true
938955
},
939956
"kernelspec": {

0 commit comments

Comments
 (0)