Is it possible to use static/class variables or otherwise save attributes from an object without using Trainable.save? If not, is there some way to explicitly warn users against this using metaclasses?
Here's an example script that might fall under ray gotchas:
from ray import tune
from ray.rllib.utils.annotations import override
from typing import Dict
class Inner(tune.Trainable):
b = 0
@override(tune.Trainable)
def setup(self, config: Dict):
self.a = 0
@override(tune.Trainable)
def step(self):
self.a += 1
Inner.b += 1
return {"inner": self.a, "inner_cls": Inner.b}
class Outer(tune.Trainable):
@override(tune.Trainable)
def setup(self, config: Dict):
self.ctr = 0
@override(tune.Trainable)
def step(self):
tune.run(Inner, stop={"training_iteration": 5})
self.ctr += 1
return {"outer": self.ctr}
def run(cls, stop):
obj = cls()
obj.setup(config={})
for _ in range(stop):
print(obj.step())
class PlainInner:
b = 0
def setup(self, config: Dict):
self.a = 0
def step(self):
self.a += 1
PlainInner.b += 1
return {"inner": self.a, "inner_cls": PlainInner.b}
class PlainOuter:
def setup(self, config: Dict):
self.ctr = 0
def step(self):
run(PlainInner, 5)
self.ctr += 1
return {"outer": self.ctr}
if __name__=="__main__":
tune.run(Outer, stop={"training_iteration": 5})
run(PlainOuter, 5)
Description
Is it possible to use static/class variables or otherwise save attributes from an object without using
Trainable.save
? If not, is there some way to explicitly warn users against this using metaclasses?Here's an example script that might fall under ray gotchas:
Outer.b
is 5, butPlainOuter.b
is 25.Use case
No response