code: def load(self, data, offset):
      self.version = struct.unpack(
          "<I", bytes(data[offset : offset + 4])
      )[0]
      offset += 4
  
      if self.version == 0:
          params = OptimizationParamsV0()
          offset = params.load(data, offset)
          self.past = params.past
          self.lbfgs_m = params.lbfgs_m
          self.nx = struct.unpack(
              "N", bytes(data[offset : offset + 8])
          )[0]
          offset += 8
          self.iter = struct.unpack(
              "<i", bytes(data[offset : offset + 4])
          )[0]
          offset += 4
          self.just_initialized = bool(
              struct.unpack("<i", bytes(data[offset : offset + 4]))[0]
          )
          offset += 4
          self.type = params.type
  
          self.adam_m = Tensor("f", [self.nx])
          self.adam_v = Tensor("f", [self.nx])
          self.adam_pf = Tensor(
              "f", [self.past] if self.past > 0 else []
          )
  
          self.lbfgs_x = Tensor("f", [self.nx])
          self.lbfgs_xp = Tensor("f", [self.nx])
          self.lbfgs_g = Tensor("f", [self.nx])
          self.lbfgs_gp = Tensor("f", [self.nx])
          self.lbfgs_d = Tensor("f", [self.nx])
          self.lbfgs_pf = Tensor(
              "f", [self.past] if self.past > 0 else []
          )
          self.lbfgs_lmal = Tensor("f", [self.lbfgs_m])
          self.lbfgs_lmys = Tensor("f", [self.lbfgs_m])
          self.lbfgs_lms = Tensor("f", [self.nx, self.lbfgs_m])
          self.lbfgs_lmy = Tensor("f", [self.nx, self.lbfgs_m])
  
          if self.type == 0:
              # these tensors are stored, but we don't need their data
              x = Tensor("f", [self.nx])
              g = Tensor("f", [self.nx])
              g2 = Tensor("f", [self.nx])
              mh = Tensor("f", [self.nx])
              vh = Tensor("f", [self.nx])
  
              offset = x.load(data, offset)
              offset = g.load(data, offset)
              offset = g2.load(data, offset)
              offset = self.adam_m.load(data, offset)
              offset = self.adam_v.load(data, offset)
              offset = mh.load(data, offset)
              offset = vh.load(data, offset)
              offset = self.adam_pf.load(data, offset)
  
              self.adam_fx_best = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.adam_fx_prev = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.adam_n_no_improvement = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
  
          elif self.type == 1:
              offset = self.lbfgs_x.load(data, offset)
              offset = self.lbfgs_xp.load(data, offset)
              offset = self.lbfgs_g.load(data, offset)
              offset = self.lbfgs_gp.load(data, offset)
              offset = self.lbfgs_d.load(data, offset)
              offset = self.lbfgs_pf.load(data, offset)
              offset = self.lbfgs_lmal.load(data, offset)
              offset = self.lbfgs_lmys.load(data, offset)
              offset = self.lbfgs_lms.load(data, offset)
              offset = self.lbfgs_lmy.load(data, offset)
  
              self.lbfgs_fx_best = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_step = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_j = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_k = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_end = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_n_no_improvement = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
  
          else:
              raise ValueError("Unknown optimizer type")
  
      elif self.version == 1:
          self.past = struct.unpack(
              "<i", bytes(data[offset : offset + 4])
          )[0]
          offset += 4
          self.lbfgs_m = struct.unpack(
              "<i", bytes(data[offset : offset + 4])
          )[0]
          offset += 4
          self.nx = struct.unpack(
              "N", bytes(data[offset : offset + 8])
          )[0]
          offset += 8
          self.iter = struct.unpack(
              "<i", bytes(data[offset : offset + 4])
          )[0]
          offset += 4
          self.just_initialized = bool(
              struct.unpack("<i", bytes(data[offset : offset + 4]))[0]
          )
          offset += 4
  
          self.adam_m = Tensor("f", [self.nx])
          self.adam_v = Tensor("f", [self.nx])
          self.adam_pf = Tensor(
              "f", [self.past] if self.past > 0 else []
          )
  
          self.lbfgs_x = Tensor("f", [self.nx])
          self.lbfgs_xp = Tensor("f", [self.nx])
          self.lbfgs_g = Tensor("f", [self.nx])
          self.lbfgs_gp = Tensor("f", [self.nx])
          self.lbfgs_d = Tensor("f", [self.nx])
          self.lbfgs_pf = Tensor(
              "f", [self.past] if self.past > 0 else []
          )
          self.lbfgs_lmal = Tensor("f", [self.lbfgs_m])
          self.lbfgs_lmys = Tensor("f", [self.lbfgs_m])
          self.lbfgs_lms = Tensor("f", [self.nx, self.lbfgs_m])
          self.lbfgs_lmy = Tensor("f", [self.nx, self.lbfgs_m])
  
          # forgot to save type in version 1:
          # guess self.type from number of remaining bytes
          size_type_0 = 12 + sum(
              [
                  t.max_storage_size()
                  for t in [self.adam_m, self.adam_v]
                  + ([self.adam_pf] if (self.past > 0) else [])
              ]
          )
          size_type_1 = 24 + sum(
              [
                  t.max_storage_size()
                  for t in [
                      self.lbfgs_x,
                      self.lbfgs_xp,
                      self.lbfgs_g,
                      self.lbfgs_gp,
                      self.lbfgs_d,
                      self.lbfgs_pf,
                      self.lbfgs_lmal,
                      self.lbfgs_lmys,
                      self.lbfgs_lms,
                      self.lbfgs_lmy,
                  ]
                  + ([self.lbfgs_pf] if (self.past > 0) else [])
              ]
          )
          # due to alignment padding the size might not by exact
          # but the difference in size for both types is significant,
          # so we can just use whichever is closest
          remaining = len(data) - offset
          if abs(remaining - size_type_0) < abs(
              remaining - size_type_1
          ):
              self.type = 0
          else:
              self.type = 1
  
          if self.type == 0:
              offset = self.adam_m.load(data, offset)
              offset = self.adam_v.load(data, offset)
              offset = self.adam_pf.load(data, offset)
  
              self.adam_fx_best = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.adam_fx_prev = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.adam_n_no_improvement = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
  
          elif self.type == 1:
              offset = self.lbfgs_x.load(data, offset)
              offset = self.lbfgs_xp.load(data, offset)
              offset = self.lbfgs_g.load(data, offset)
              offset = self.lbfgs_gp.load(data, offset)
              offset = self.lbfgs_d.load(data, offset)
              offset = self.lbfgs_pf.load(data, offset)
              offset = self.lbfgs_lmal.load(data, offset)
              offset = self.lbfgs_lmys.load(data, offset)
              offset = self.lbfgs_lms.load(data, offset)
              offset = self.lbfgs_lmy.load(data, offset)
  
              self.lbfgs_fx_best = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_step = struct.unpack(
                  "<f", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_j = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_k = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_end = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
              self.lbfgs_n_no_improvement = struct.unpack(
                  "<i", bytes(data[offset : offset + 4])
              )[0]
              offset += 4
  
      else:
          raise ValueError("Invalid version of checkpoint file")
  
      return offset
  
imports: import argparse
  import os
  import struct
  import sys
  import numpy
  from pathlib import Path
  import gguf
label_desc: Use image node_id 2 for calling the OptimizationContext obj's underlying member method code with example usage: obj.load(data, offset) and returns: offset