pygmtools.utils.set_backend

pygmtools.utils.set_backend(new_backend: str)[source]

Set the default backend. The current backend information is stored in the variable pygmtools.BACKEND.

Parameters

new_backend – string, name of the new backend. Possible values are ``[‘numpy’, ‘pytorch’, ‘jittor’,

‘paddle’, ‘mindspore’, ‘tensorflow’]``

Note

You can change the backend by directly assign new values to pygmtools.BACKEND. However, we encourage you using this pygmtools.utils.set_backend function because it will do a spelling check and check if that package is installed.

Example
>>> import pygmtools as pygm # numpy is the default backend
>>> pygm.set_backend('pytorch') # set backend to pytorch, it will through an error if torch is not installed

>>> pygm.set_backend('tf') # throw an error, provide potential matches
ValueError: Unknown backend tf. Did you mean tensorflow? Supported backends: ['numpy', 'pytorch', 'jittor', 'paddle', 'mindspore', 'tensorflow']
>>> pygm.set_backend('tensorflow') # this is the correct key and will work