Learner Core

Core DataPipes for building Learners

LearnerBase

 LearnerBase (*args, **kwds)

Combines models,dataloaders, and optimizers together for running a training pipeline.


LearnerHead

 LearnerHead (*args, **kwds)

Initialize self. See help(type(self)) for accurate signature.

Warning: Pickling the LearnerBase will exclude the ’_dls’,‘opt’,‘iterable’ fields since these aren’t easily picklable (yet).

from fastrl.torch_core import *
from fastrl.agents.dqn.basic import *
from fastrl.agents.core import *
from fastrl.agents.discrete import *
from fastrl.data.block import *
from fastrl.envs.gym import *
from fastrl.loggers.vscode_visualizers import *
# Setup up the core NN
torch.manual_seed(0)
model = DQN(4,2)
# Setup the agent
agent = AgentBase(model,[])
agent = StepFieldSelector(agent,field='state')
# All the things that make this agent unique and special
# In this instance, all this module does is pass the action directly through to the model.
agent = SimpleModelRunner(agent)
agent = ArgMaxer(agent,only_idx=True)
agent = NumpyConverter(agent)
agent = PyPrimativeConverter(agent)
# Bring everything together into the AgentHead where actions will be passed and then run through the pipeline
agent = AgentHead(agent)
# Setup the DataBlock
block = DataBlock(
    GymTransformBlock(agent=agent,nsteps=1,nskips=1,firstlast=False,n=100,bs=1),
    (GymTransformBlock(agent=agent,nsteps=1,nskips=1,firstlast=False,n=100,bs=1,include_images=True),VSCodeTransformBlock())
)

dls = L(block.dataloaders(['CartPole-v1']*1,num_workers=0))
def TestLearner(model,dls):
    learner = LearnerBase(model,dls)
    learner = LearnerHead(learner)
    return learner
learner = TestLearner(model,dls)

StepBatcher

 StepBatcher (*args, **kwds)

Converts multiple StepType into a single StepType with the fields concated.