How the neetbox.integrations
are designed
#79
Replies: 11 comments 1 reply
-
I think we can use |
Beta Was this translation helpful? Give feedback.
-
Currently, I'm trying with patch as a workaround. But I think it's not gonna be so easy. I will put my new ideas here as soon I get them. Not to mention, an example here: # package neetbox.integrations.tensorboard
from neetbox.logging.logger import Logger
from neetbox.utils.utils import patch
from neetbox.integrations import pkg
from typing import Any
assert pkg.is_installed('tensorboard',try_install_if_not=True)
import tensorboard
@patch
def write_tensorboard(self:Logger, what:Any,):
pass # to write something into tensorboard The code adds a new function caller 'write_tensorboard' into class Logger. So later in my code, I can do such thing: from neetbox.logging import logger
import neetbox.integrations
logger.write_tensorboard(whatever) |
Beta Was this translation helpful? Give feedback.
-
It's a kinda solution, but idk how my IDEs perform with the code completion... I'll find it out later when I have time. |
Beta Was this translation helpful? Give feedback.
-
Another example for |
Beta Was this translation helpful? Give feedback.
-
@PaperCube @PommesPeter What do you think? Do you find it plausible? |
Beta Was this translation helpful? Give feedback.
-
I'm running out of ideas. I'm rubbish indeed. |
Beta Was this translation helpful? Give feedback.
-
I think |
Beta Was this translation helpful? Give feedback.
-
another approach scans all submodules in it's kinda piece of scaffold, I will make it into a stronger implementation later, just keep you guys up to date. |
Beta Was this translation helpful? Give feedback.
-
So, how should we design the |
Beta Was this translation helpful? Give feedback.
-
from neetbox.extension import on_workspace_load
# run this function on workspace initialization
@on_workspace_load(name="hardware-monit")
def load_monit_hardware():
cfg = get_module_level_config()
if cfg["monit"]: # if do monit hardware
hardware.set_update_intervel(cfg["interval"])
# watch updates in daemon
@watch(name="hardware", _channel=SYSTEM_CHANNEL, interval=cfg["interval"], initiative=False)
def update_env_stat():
return hardware.json() once after neetbox loads up its config, it runs this function. Therefore, you can add custom sub-modules as extensions in |
Beta Was this translation helpful? Give feedback.
-
Important updatesin #76, there is a patch fix (ef5b792) which allows submodules in neetbox.extension to provide default config. Example: in from neetbox.config import export_default_config, get_module_level_config
from neetbox.extension import on_workspace_loaded
...
@export_default_config()
def return_default_config() -> dict:
return {"monit": True, "interval": 0.5}
# watch updates in daemon
@on_workspace_loaded(name="hardware-monit")
def load_monit_hardware():
cfg = get_module_level_config()
if cfg["monit"]: # if do monit hardware
hardware.set_update_intervel(cfg["interval"])
# watch updates in daemon
@watch(name="hardware", _channel=SYSTEM_CHANNEL, interval=cfg["interval"], initiative=False)
def update_env_stat():
return hardware.json() in code above, [extension.environment.hardware]
monit = true
interval = 0.5 plus, |
Beta Was this translation helpful? Give feedback.
-
The problem is, as we want a not-dependency-intensive neetbox, we are trying to remove codes with heavy dependencies from core functions. To be specific, in order to avoid installing package 'thop'(which depends on torch) for non-torch users, we have removed
import torch
from the headings of each python file into the line where the packages are required to overcome the import errors for most of the packages. For example, inneetbox.torch.profile
:was changed to:
It was simple until we added
neetbox.integrations
. I'm not a pro for Python things, but I found it much more clear if we move things related to third parties intoneetbox.integrations
. So what does theneetbox.integrations
stand for? In general,neetbox.integrations
contains plugins for the original neetbox codes which empowers neetbox with third-party-compbilities.I first mentioned the idea in #19 , in which I suggest that we should move 'nvidia-smi' and 'conda' command line getters out of
neetbox.utils
. However, since I'm a little confused about how to effectively addplugins
into python class, I'm not sure what to do next to form the general framework forneetbox.integrations
. Anyway, I think I need some help. Further discussions and methods are welcomed and appreciated.Beta Was this translation helpful? Give feedback.
All reactions