Skip to content

Commit ccae258

Browse files
authored
Document AppleOps and MPSOps (#929)
* Document AppleOps and MPSOps * Reformat Ops table - Sort alphabetically. - Note that `AppleOps` is new in 9.0. * Missing comma
1 parent 2a0b9c1 commit ccae258

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

website/docs/api-backends.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ specialized versions can be called for different backends. You can also create
1717
your own `Ops` subclasses with specialized routines for your layers, and use the
1818
[`set_current_ops`](#set_current_ops) function to change the default.
1919

20-
| Backend | CPU | GPU | TPU | Description |
21-
| ---------- | :----------------: | :----------------: | :---------------: | ----------------------------------------------------------------------------------------------------- |
22-
| `NumpyOps` | <i name="yes"></i> | <i name="no"></i> | <i name="no"></i> | Execute via `numpy`, [`blis`](https://github.com/explosion/cython-blis) (optional) and custom Cython. |
23-
| `CupyOps` | <i name="no"></i> | <i name="yes"></i> | <i name="no"></i> | Execute via [`cupy`](https://cupy.chainer.org/) and custom CUDA. |
20+
| Backend | CPU | GPU | TPU | Description |
21+
| ---------- | :----------------: | :----------------: | :---------------: | ----------------------------------------------------------------------------------------------------------- |
22+
| `AppleOps` | <i name="yes"></i> | <i name="no"></i> | <i name="no"></i> | Use AMX matrix multiplication units on Apple Silicon Macs. Added in Thinc 9.0. |
23+
| `CupyOps` | <i name="no"></i> | <i name="yes"></i> | <i name="no"></i> | Execute via [`cupy`](https://cupy.chainer.org/) and custom CUDA. |
24+
| `MPSOps` | <i name="yes"></i> | <i name="yes"></i> | <i name="no"></i> | Use the GPU on Apple Silicon Macs for PyTorch models, use AMX matrix multiplication units for Thinc Models. |
25+
| `NumpyOps` | <i name="yes"></i> | <i name="no"></i> | <i name="no"></i> | Execute via `numpy`, [`blis`](https://github.com/explosion/cython-blis) (optional) and custom Cython. |
2426

2527
## Ops {#ops tag="class"}
2628

27-
The `Ops` class is typically not used directly but via `NumpyOps` or `CupyOps`,
28-
which are subclasses of `Ops` and implement a **more efficient subset of the
29-
methods**. You also have access to the ops via the
29+
The `Ops` class is typically not used directly but via `NumpyOps`, `AppleOps`,
30+
`CupyOps` or `MPSOps`, which are subclasses of `Ops` and implement a **more
31+
efficient subset of the methods**. You also have access to the ops via the
3032
[`Model.ops`](/docs/api-model#attributes) attribute. The documented methods
3133
below list which backends provide optimized and more efficient versions
3234
(indicated by <i name="yes"></i>), and which use the default implementation.
@@ -56,7 +58,7 @@ use_ops(blis_ops)
5658

5759
| Name | Type | Description |
5860
| ------------- | ------------ | ---------------------------------------------------------------------------------------- |
59-
| `name` | <tt>str</tt> | **Class attribute:** Backend name, `"numpy"` or `"cupy"`. |
61+
| `name` | <tt>str</tt> | **Class attribute:** Backend name, `"numpy"`, `"apple"`, `"cupy"` or `"mps"`. |
6062
| `xp` | <tt>Xp</tt> | **Class attribute:** `numpy` or `cupy`. |
6163
| `device_type` | <tt>str</tt> | The device type to use, if available for the given backend: `"cpu"`, `"gpu"` or `"tpu"`. |
6264
| `device_id` | <tt>int</tt> | The device ID to use, if available for the given backend. |
@@ -1553,7 +1555,7 @@ numpy_ops = get_ops("numpy")
15531555

15541556
| Argument | Type | Description |
15551557
| ----------- | ------------ | ----------------------------------------------------- |
1556-
| `ops` | <tt>str</tt> | `"numpy"` or `"cupy"`. |
1558+
| `ops` | <tt>str</tt> | `"numpy"`, `"apple"`, `"cupy"` or `"mps"`. |
15571559
| `**kwargs` | | Optional arguments passed to [`Ops.__init__`](#init). |
15581560
| **RETURNS** | <tt>Ops</tt> | The backend object. |
15591561

@@ -1572,7 +1574,7 @@ with use_ops("cupy"):
15721574

15731575
| Argument | Type | Description |
15741576
| ---------- | ------------ | ----------------------------------------------------- |
1575-
| `ops` | <tt>str</tt> | `"numpy"` or `"cupy"`. |
1577+
| `ops` | <tt>str</tt> | `"numpy"`, `"apple"`, `"cupy"` or `"mps"`. |
15761578
| `**kwargs` | | Optional arguments passed to [`Ops.__init__`](#init). |
15771579

15781580
### get_current_ops {#get_current_ops tag="function"}

website/docs/api-model.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,19 @@ model = Model(
8484
)
8585
```
8686

87-
| Argument | Type | Description |
88-
| -------------- | ------------------------------------------- | --------------------------------------------------------------------------------------- |
89-
| `name` | <tt>str</tt> | The name of the layer type. |
90-
| `forward` | <tt>Callable</tt> | Function to compute the forward result and the backpropagation callback. |
91-
| _keyword-only_ | | |
92-
| `init` | <tt>Callable</tt> | Function to define the initialization logic. |
93-
| `dims` | <tt>Dict[str, Optional[int]]</tt> | Dictionary describing the model's dimensions. Map unknown dimensions to `None`. |
94-
| `params` | <tt>Dict[str, Optional[FloatsXd]]</tt> | Dictionary with the model's parameters. Set currently unavailable parameters to `None`. |
95-
| `refs` | <tt>Dict[str, Optional[Model]]</tt> | Dictionary mapping specific nodes (sublayers) of the network to a name. |
96-
| `attrs` | <tt>Dict[str, Any]</tt> | Dictionary of non-parameter attributes. |
97-
| `layers` | <tt>List[Model]</tt> | List of child layers. |
98-
| `shims` | <tt>List[Shim]</tt> | List of interfaces for external models. |
99-
| `ops` | <tt>Optional[Union[NumpyOps, CupyOps]]</tt> | An `Ops` instance, which provides mathematical and memory operations. |
87+
| Argument | Type | Description |
88+
| -------------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
89+
| `name` | <tt>str</tt> | The name of the layer type. |
90+
| `forward` | <tt>Callable</tt> | Function to compute the forward result and the backpropagation callback. |
91+
| _keyword-only_ | | |
92+
| `init` | <tt>Callable</tt> | Function to define the initialization logic. |
93+
| `dims` | <tt>Dict[str, Optional[int]]</tt> | Dictionary describing the model's dimensions. Map unknown dimensions to `None`. |
94+
| `params` | <tt>Dict[str, Optional[FloatsXd]]</tt> | Dictionary with the model's parameters. Set currently unavailable parameters to `None`. |
95+
| `refs` | <tt>Dict[str, Optional[Model]]</tt> | Dictionary mapping specific nodes (sublayers) of the network to a name. |
96+
| `attrs` | <tt>Dict[str, Any]</tt> | Dictionary of non-parameter attributes. |
97+
| `layers` | <tt>List[Model]</tt> | List of child layers. |
98+
| `shims` | <tt>List[Shim]</tt> | List of interfaces for external models. |
99+
| `ops` | <tt>Optional[Union[NumpyOps, AppleOps, CupyOps, MPSOps]]</tt> | An `Ops` instance, which provides mathematical and memory operations. |
100100

101101
### Model.define_operators {#define_operators tag="classmethod,contextmanager"}
102102

@@ -260,17 +260,17 @@ for node in model.walk():
260260

261261
The `walk` method supports three iteration orders through the `order` argument:
262262

263-
* `"bfs"`: breadth-first. Iteration order of the example above:
264-
*1 - 2 - 4 - 3 - 5*
265-
* `"dfs_pre"`: depth-first preorder, outputs a node before its children.
266-
Iteration order of the example above: *1 - 2 - 3 - 4 - 5*
267-
* `"dfs_post"`: depth-first postorder, outputs children before a node itself.
268-
Iteration order of the example above: *3 - 2 - 5 - 4 - 1*
263+
- `"bfs"`: breadth-first. Iteration order of the example above: _1 - 2 - 4 - 3 -
264+
5_
265+
- `"dfs_pre"`: depth-first preorder, outputs a node before its children.
266+
Iteration order of the example above: _1 - 2 - 3 - 4 - 5_
267+
- `"dfs_post"`: depth-first postorder, outputs children before a node itself.
268+
Iteration order of the example above: _3 - 2 - 5 - 4 - 1_
269269

270-
| Argument | Type | Description |
271-
|-------------|--------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
270+
| Argument | Type | Description |
271+
| ----------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
272272
| `order` | <tt>str</tt> | Node iteration order. `"bfs"` (breadth-first), `"dfs_pre"` (depth-first preorder), `"dfs_post"` (depth-first postorder) Default: `"bfs"`. |
273-
| **RETURNS** | <tt>Iterable[Model]</tt> | The layers of the model. |
273+
| **RETURNS** | <tt>Iterable[Model]</tt> | The layers of the model. |
274274

275275
### Model.remove_node {#remove_node tag="method"}
276276

@@ -329,9 +329,9 @@ assert model.get_dim("nI") == 16
329329
Retrieve the value of a dimension of the given name, or `None` if the dimension
330330
is either unregistered or the value is currently unset.
331331

332-
| Argument | Type | Description |
333-
| ----------- | --------------------- | --------------------------------------- |
334-
| `name` | <tt>str</tt> | The name of the dimension, e.g. `"nO"`. |
332+
| Argument | Type | Description |
333+
| ----------- | ---------------------- | --------------------------------------- |
334+
| `name` | <tt>str</tt> | The name of the dimension, e.g. `"nO"`. |
335335
| **RETURNS** | <tt>Optional[int]</tt> | The size of the dimension, or `None`. |
336336

337337
### Model.set_dim {#set_dim tag="method"}

0 commit comments

Comments
 (0)