Docs fixes for viewer elements (#1770)

This commit is contained in:
Brent Yi authored and GitHub committed 2023-04-18 19:15:29 -07:00
1 parent 6a06710f49
commit 63919c0db2
1 file changed
+6 -7
+6 -7
View File
@@ -33,16 +33,15 @@ current_value = self.custom_value.value
**Callbacks**
You can register a callback that will be called whenever a new value for your GUI element is available. For example, one can use a callback to update config parameters when elements are changed:
```python
def on_change_callback(handle: GuiHandle):
self.config.example_parameter = handle.get_value()
def on_change_callback(handle: ViewerCheckbox) -> None:
self.config.example_parameter = handle.value
self.custom_checkbox = ViewerCheckbox(
name="Checkbox",
default_value = False,
cb_hook = on_change_callback
default_value=False,
cb_hook=on_change_callback,
)
```
The GuiHandle value is a viser object which you can use to get the new value.
**Thread safety**
Note that `ViewerElement` values can change asynchronously to model execution. So, it's best practice to store the value of a viewer element once at the beginning
@@ -63,13 +62,13 @@ class MyModel(Model):
You can write to a viewer element in Python, which provides a convenient way to track values in your code without the need for wandb/tensorboard or relying on `print` statements.
```python
self.custom_value = x
self.custom_value.value = x
```
:::{admonition} Warning
:class: warning
Note that updating module state while training can have unexpected side effects. It is up to the user to ensure that GUI actions are safe. In most cases, we recommend wrapping GUI related logic in `if self.training:` to ensure that the effects are only applied during inference.
Updating module state while training can have unexpected side effects. It is up to the user to ensure that GUI actions are safe. Conditioning on `self.training` can help determine whether effects are applied during forward passes for training or rendering.
:::
## Example Elements