docstr: Provides an easy to use class for pretraining and evaluating a Reformer Model.
  
  :param dataset: (torch.utils.data.Dataset) containing all of the data you wish to utilize during training.
  :param model: (reformer_pytorch.Reformer)
  :param tokenizer: (transformers.PreTrainedTokenizer) defaults to BertTokenizer ('bert-base-case')
  :param device: provide manual device placement. If None, will default to cuda:0 if available.
  :param tb_writer: (bool) Whether to write to tensorboard or not.
  :param tb_dir: (str) Where to write TB logs to.
  :param log_dir: (str) Where to write generic logs to.
docstr_tok: ["Provides","an","easy","to","use","class","for","pretraining","and","evaluating","a","Reformer","Model",".",":","param","dataset",":","(","torch.utils.data.Dataset",")","containing","all","of","the","data","you","wish","to","utilize","during","training",".",":","param","model",":","(","reformer_pytorch.Reformer",")",":","param","tokenizer",":","(","transformers.PreTrainedTokenizer",")","defaults","to","BertTokenizer","(","'bert-base-case","'",")",":","param","device",":","provide","manual","device","placement",".","If","None",",","will","default","to","cuda:0","if","available",".",":","param","tb_writer",":","(","bool",")","Whether","to","write","to","tensorboard","or","not",".",":","param","tb_dir",":","(","str",")","Where","to","write","TB","logs","to",".",":","param","log_dir",":","(","str",")","Where","to","write","generic","logs","to","."]
code: def __init__(
      self,
      dataset,
      model,
      tokenizer,
      device=None,
      train_batch_size=8,
      eval_batch_size=None,
      tb_writer=True,
      tb_dir="./tb_logs",
      log_dir="./logs",
  ):
      """
      Provides an easy to use class for pretraining and evaluating a Reformer Model.
  
      :param dataset: (torch.utils.data.Dataset) containing all of the data you wish to utilize during training.
      :param model: (reformer_pytorch.Reformer)
      :param tokenizer: (transformers.PreTrainedTokenizer) defaults to BertTokenizer ('bert-base-case')
      :param device: provide manual device placement. If None, will default to cuda:0 if available.
      :param tb_writer: (bool) Whether to write to tensorboard or not.
      :param tb_dir: (str) Where to write TB logs to.
      :param log_dir: (str) Where to write generic logs to.
      """
  
      self.dataset = dataset
      self.model = model
      self.tokenizer = tokenizer
      self.device = device
      self.n_gpu = (
          torch.cuda.device_count() if torch.cuda.is_available() else 0
      )
      self.train_batch_size = train_batch_size
      self.eval_batch_size = eval_batch_size
      self.tb_writer = tb_writer
      self.log_dir = log_dir
  
      if tokenizer is None:
          self.tokenizer = BertTokenizer.from_pretrained(
              "bert-base-cased"
          )
  
      if device is None:
          self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
  
      if eval_batch_size is None:
          self.eval_batch_size = train_batch_size
  
      if tb_writer:
          from torch.utils.tensorboard import SummaryWriter
  
          self.writer = SummaryWriter(log_dir=tb_dir)
  
      logging.basicConfig(
          filename=f"{log_dir}/{datetime.now().date()}.log",
          level=logging.INFO,
      )
  
imports: import re
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.utils.data import Dataset, DataLoader, random_split
  from tqdm import tqdm
  from reformer_pytorch import Reformer, ReformerLM
  from transformers import BertTokenizer, PreTrainedTokenizer
  from fairseq.optim.adafactor import Adafactor
  import os
  import json
  import logging
  from datetime import datetime
label_desc: Use image node_id 1 to create a new ReformerTrainer object from inherited base classes: object with example: obj = ReformerTrainer(dataset, model, tokenizer, device, train_batch_size, eval_batch_size, tb_writer, tb_dir, log_dir)