tests/testthat/_snaps/callbacks.md

callback lr scheduler

Code
  expect_message({
    output <- mod %>% set_hparams(input_size = 10, output_size = 1) %>% fit(dl,
      verbose = FALSE, epochs = 5, callbacks = list(luz_callback_lr_scheduler(
        torch::lr_multiplicative, verbose = TRUE, lr_lambda = function(epoch) 0.5)))
  })
Message
  Adjusting learning rate of group 1 to 0.0005
  Adjusting learning rate of group 1 to 0.0003
  Adjusting learning rate of group 1 to 0.0001
  Adjusting learning rate of group 1 to 0.0001
  Adjusting learning rate of group 1 to 0.0000
Code
  expect_message({
    output <- mod %>% set_hparams(input_size = 10, output_size = 1) %>% fit(dl,
      verbose = FALSE, epochs = 20, callbacks = list(luz_callback_lr_scheduler(
        torch::lr_reduce_on_plateau, verbose = TRUE, patience = 2, threshold = 0.1)))
  })
Message
  Epoch 7: reducing learning rate of group 1 to 1.0000e-05
  Epoch 10: reducing learning rate of group 1 to 1.0000e-06
  Epoch 13: reducing learning rate of group 1 to 1.0000e-07
  Epoch 16: reducing learning rate of group 1 to 1.0000e-08

progressbar appears with training and validation

Code
  expect_message({
    output <- mod %>% set_hparams(input_size = 10, output_size = 1) %>% fit(dl,
      verbose = TRUE, epochs = 2, valid_data = dl)
  })
Message

  1/50 [>------------------------------------------------------] - Loss: 3.2392

  2/50 [=>-----------------------------------------------------] - Loss: 2.5641

  3/50 [==>----------------------------------------------------] - Loss: 2.6243

  4/50 [===>---------------------------------------------------] - Loss: 2.3165

  5/50 [=====>-------------------------------------------------] - Loss: 2.2277

  6/50 [======>------------------------------------------------] - Loss: 2.2308

  7/50 [=======>-----------------------------------------------] - Loss: 2.0433

  8/50 [========>----------------------------------------------] - Loss: 2.0283

  9/50 [=========>---------------------------------------------] - Loss: 1.9632

  10/50 [==========>-------------------------------------------] - Loss: 1.9339

  11/50 [===========>------------------------------------------] - Loss: 1.8714

  12/50 [============>-----------------------------------------] - Loss: 1.8386

  13/50 [=============>----------------------------------------] - Loss: 1.8343

  14/50 [==============>---------------------------------------] - Loss: 1.7534

  15/50 [===============>--------------------------------------] - Loss: 1.7802

  16/50 [================>-------------------------------------] - Loss: 1.7656

  17/50 [=================>------------------------------------] - Loss: 1.7414

  18/50 [==================>-----------------------------------] - Loss: 1.7096

  19/50 [====================>---------------------------------] - Loss: 1.7159

  20/50 [=====================>--------------------------------] - Loss: 1.6838

  21/50 [======================>--------------------------------] - Loss: 1.658

  22/50 [=======================>------------------------------] - Loss: 1.7045

  23/50 [========================>-----------------------------] - Loss: 1.7719

  24/50 [=========================>-----------------------------] - Loss: 1.777

  25/50 [==========================>---------------------------] - Loss: 1.7646

  26/50 [============================>--------------------------] - Loss: 1.755

  27/50 [============================>-------------------------] - Loss: 1.7117

  28/50 [=============================>------------------------] - Loss: 1.6827

  29/50 [==============================>-----------------------] - Loss: 1.6975

  30/50 [===============================>----------------------] - Loss: 1.7005

  31/50 [==================================>---------------------] - Loss: 1.69

  32/50 [==================================>-------------------] - Loss: 1.6555

  33/50 [===================================>------------------] - Loss: 1.6458

  34/50 [====================================>-----------------] - Loss: 1.6328

  35/50 [=====================================>----------------] - Loss: 1.6116

  36/50 [======================================>---------------] - Loss: 1.6237

  37/50 [=======================================>--------------] - Loss: 1.6044

  38/50 [========================================>-------------] - Loss: 1.6068

  39/50 [==========================================>------------] - Loss: 1.601

  40/50 [==========================================>-----------] - Loss: 1.5955

  41/50 [===========================================>----------] - Loss: 1.5831

  42/50 [============================================>---------] - Loss: 1.5794

  43/50 [=============================================>--------] - Loss: 1.5718

  44/50 [===============================================>------] - Loss: 1.5717

  45/50 [================================================>-----] - Loss: 1.5656

  46/50 [=================================================>----] - Loss: 1.5815

  47/50 [==================================================>---] - Loss: 1.5662

  48/50 [===================================================>--] - Loss: 1.5549

  49/50 [====================================================>-] - Loss: 1.5511

  50/50 [======================================================] - Loss: 1.5753



  1/50 [>-------------------------------------------------------] - Loss: 3.058

  2/50 [=>-----------------------------------------------------] - Loss: 2.3999

  3/50 [==>----------------------------------------------------] - Loss: 2.4435

  4/50 [===>---------------------------------------------------] - Loss: 2.1623

  5/50 [=====>-------------------------------------------------] - Loss: 2.0719

  6/50 [======>------------------------------------------------] - Loss: 2.0865

  7/50 [=======>-----------------------------------------------] - Loss: 1.9057

  8/50 [========>-----------------------------------------------] - Loss: 1.894

  9/50 [=========>---------------------------------------------] - Loss: 1.8281

  10/50 [==========>-------------------------------------------] - Loss: 1.8074

  11/50 [===========>------------------------------------------] - Loss: 1.7501

  12/50 [============>-----------------------------------------] - Loss: 1.7246

  13/50 [=============>----------------------------------------] - Loss: 1.7198

  14/50 [==============>---------------------------------------] - Loss: 1.6425

  15/50 [===============>--------------------------------------] - Loss: 1.6708

  16/50 [================>-------------------------------------] - Loss: 1.6564

  17/50 [=================>------------------------------------] - Loss: 1.6335

  18/50 [==================>-----------------------------------] - Loss: 1.6057

  19/50 [====================>---------------------------------] - Loss: 1.6145

  20/50 [=====================>--------------------------------] - Loss: 1.5863

  21/50 [======================>-------------------------------] - Loss: 1.5612

  22/50 [=======================>------------------------------] - Loss: 1.6068

  23/50 [========================>------------------------------] - Loss: 1.673

  24/50 [=========================>----------------------------] - Loss: 1.6781

  25/50 [==========================>---------------------------] - Loss: 1.6679

  26/50 [===========================>--------------------------] - Loss: 1.6597

  27/50 [============================>-------------------------] - Loss: 1.6195

  28/50 [=============================>------------------------] - Loss: 1.5934

  29/50 [==============================>-----------------------] - Loss: 1.6095

  30/50 [===============================>----------------------] - Loss: 1.6127

  31/50 [================================>---------------------] - Loss: 1.6035

  32/50 [==================================>-------------------] - Loss: 1.5717

  33/50 [===================================>------------------] - Loss: 1.5639

  34/50 [====================================>------------------] - Loss: 1.552

  35/50 [=====================================>----------------] - Loss: 1.5323

  36/50 [======================================>---------------] - Loss: 1.5456

  37/50 [========================================>--------------] - Loss: 1.528

  38/50 [========================================>-------------] - Loss: 1.5319

  39/50 [=========================================>------------] - Loss: 1.5275

  40/50 [==========================================>-----------] - Loss: 1.5233

  41/50 [===========================================>----------] - Loss: 1.5123

  42/50 [============================================>---------] - Loss: 1.5096

  43/50 [=============================================>--------] - Loss: 1.5035

  44/50 [===============================================>------] - Loss: 1.5044

  45/50 [================================================>-----] - Loss: 1.4997

  46/50 [=================================================>----] - Loss: 1.5164

  47/50 [==================================================>---] - Loss: 1.5022

  48/50 [====================================================>--] - Loss: 1.492

  49/50 [====================================================>-] - Loss: 1.4894

  50/50 [======================================================] - Loss: 1.5147


  Train metrics: Loss: 1.5753
  Valid metrics: Loss: 1.5147
  Epoch 2/2

  1/50 [>-------------------------------------------------------] - Loss: 3.058

  2/50 [=>-----------------------------------------------------] - Loss: 2.3985

  3/50 [==>------------------------------------------------------] - Loss: 2.44

  4/50 [===>---------------------------------------------------] - Loss: 2.1585

  5/50 [=====>-------------------------------------------------] - Loss: 2.0652

  6/50 [======>------------------------------------------------] - Loss: 2.0794

  7/50 [=======>-----------------------------------------------] - Loss: 1.8978

  8/50 [========>----------------------------------------------] - Loss: 1.8849

  9/50 [=========>---------------------------------------------] - Loss: 1.8173

  10/50 [==========>-------------------------------------------] - Loss: 1.7974

  11/50 [===========>------------------------------------------] - Loss: 1.7397

  12/50 [============>-----------------------------------------] - Loss: 1.7136

  13/50 [=============>----------------------------------------] - Loss: 1.7068

  14/50 [==============>---------------------------------------] - Loss: 1.6291

  15/50 [===============>--------------------------------------] - Loss: 1.6564

  16/50 [================>-------------------------------------] - Loss: 1.6399

  17/50 [=================>------------------------------------] - Loss: 1.6159

  18/50 [==================>-----------------------------------] - Loss: 1.5883

  19/50 [====================>---------------------------------] - Loss: 1.5962

  20/50 [=====================>--------------------------------] - Loss: 1.5686

  21/50 [======================>-------------------------------] - Loss: 1.5415

  22/50 [=======================>-------------------------------] - Loss: 1.584

  23/50 [========================>-----------------------------] - Loss: 1.6469

  24/50 [=========================>----------------------------] - Loss: 1.6496

  25/50 [==========================>---------------------------] - Loss: 1.6391

  26/50 [===========================>--------------------------] - Loss: 1.6293

  27/50 [============================>-------------------------] - Loss: 1.5901

  28/50 [=============================>------------------------] - Loss: 1.5647

  29/50 [==============================>-----------------------] - Loss: 1.5801

  30/50 [===============================>----------------------] - Loss: 1.5801

  31/50 [================================>---------------------] - Loss: 1.5702

  32/50 [==================================>-------------------] - Loss: 1.5394

  33/50 [===================================>------------------] - Loss: 1.5315

  34/50 [====================================>-----------------] - Loss: 1.5181

  35/50 [=====================================>----------------] - Loss: 1.4979

  36/50 [======================================>---------------] - Loss: 1.5094

  37/50 [=======================================>--------------] - Loss: 1.4922

  38/50 [========================================>-------------] - Loss: 1.4961

  39/50 [=========================================>------------] - Loss: 1.4917

  40/50 [==========================================>-----------] - Loss: 1.4872

  41/50 [============================================>----------] - Loss: 1.476

  42/50 [============================================>---------] - Loss: 1.4717

  43/50 [=============================================>--------] - Loss: 1.4651

  44/50 [===============================================>------] - Loss: 1.4644

  45/50 [================================================>-----] - Loss: 1.4604

  46/50 [=================================================>----] - Loss: 1.4737

  47/50 [==================================================>---] - Loss: 1.4585

  48/50 [===================================================>--] - Loss: 1.4468

  49/50 [=====================================================>-] - Loss: 1.443

  50/50 [======================================================] - Loss: 1.4667



  1/50 [>------------------------------------------------------] - Loss: 2.9115

  2/50 [=>-----------------------------------------------------] - Loss: 2.2618

  3/50 [==>----------------------------------------------------] - Loss: 2.2873

  4/50 [===>---------------------------------------------------] - Loss: 2.0295

  5/50 [=====>-------------------------------------------------] - Loss: 1.9356

  6/50 [======>------------------------------------------------] - Loss: 1.9591

  7/50 [=======>-----------------------------------------------] - Loss: 1.7846

  8/50 [========>----------------------------------------------] - Loss: 1.7735

  9/50 [=========>---------------------------------------------] - Loss: 1.7053

  10/50 [==========>--------------------------------------------] - Loss: 1.693

  11/50 [===========>------------------------------------------] - Loss: 1.6397

  12/50 [============>-----------------------------------------] - Loss: 1.6196

  13/50 [=============>----------------------------------------] - Loss: 1.6121

  14/50 [==============>---------------------------------------] - Loss: 1.5375

  15/50 [===============>--------------------------------------] - Loss: 1.5657

  16/50 [================>-------------------------------------] - Loss: 1.5494

  17/50 [=================>------------------------------------] - Loss: 1.5263

  18/50 [==================>-----------------------------------] - Loss: 1.5022

  19/50 [====================>---------------------------------] - Loss: 1.5122

  20/50 [=====================>---------------------------------] - Loss: 1.488

  21/50 [======================>-------------------------------] - Loss: 1.4613

  22/50 [=======================>------------------------------] - Loss: 1.5028

  23/50 [========================>-----------------------------] - Loss: 1.5645

  24/50 [=========================>----------------------------] - Loss: 1.5671

  25/50 [==========================>---------------------------] - Loss: 1.5585

  26/50 [===========================>--------------------------] - Loss: 1.5498

  27/50 [============================>-------------------------] - Loss: 1.5131

  28/50 [=============================>------------------------] - Loss: 1.4901

  29/50 [==============================>-----------------------] - Loss: 1.5067

  30/50 [===============================>----------------------] - Loss: 1.5068

  31/50 [=================================>---------------------] - Loss: 1.498

  32/50 [==================================>-------------------] - Loss: 1.4695

  33/50 [===================================>------------------] - Loss: 1.4631

  34/50 [====================================>-----------------] - Loss: 1.4507

  35/50 [=====================================>----------------] - Loss: 1.4318

  36/50 [======================================>---------------] - Loss: 1.4442

  37/50 [=======================================>--------------] - Loss: 1.4285

  38/50 [========================================>-------------] - Loss: 1.4337

  39/50 [=========================================>------------] - Loss: 1.4304

  40/50 [===========================================>-----------] - Loss: 1.427

  41/50 [============================================>----------] - Loss: 1.417

  42/50 [============================================>---------] - Loss: 1.4135

  43/50 [=============================================>--------] - Loss: 1.4081

  44/50 [===============================================>------] - Loss: 1.4083

  45/50 [================================================>-----] - Loss: 1.4054

  46/50 [=================================================>----] - Loss: 1.4193

  47/50 [==================================================>---] - Loss: 1.4052

  48/50 [===================================================>--] - Loss: 1.3944

  49/50 [====================================================>-] - Loss: 1.3916

  50/50 [======================================================] - Loss: 1.4162


  Train metrics: Loss: 1.4667
  Valid metrics: Loss: 1.4162

improve error message when you provide a unitinitilized callback

x Callbacks must have class <LuzCallback> but got <function>
i Perhaps you forgot to initialize the callback?

can get progress when using iterable datasets

Code
  expect_message({
    output <- mod %>% set_hparams(input_size = 10, output_size = 1) %>% fit(
      get_iterable_ds(), verbose = TRUE, epochs = 2, valid_data = get_iterable_ds(),
      )
  })
Message

  1/unk [-] - Loss: 1.776

  2/unk [\] - Loss: 1.6358

  3/unk [|] - Loss: 1.6954

  1/unk [-] - Loss: 1.664

  2/unk [\] - Loss: 1.4837

  3/unk [|] - Loss: 1.6957

  4/unk [/] - Loss: 1.3467 
  Train metrics: Loss: 1.6954
  Valid metrics: Loss: 1.3467
  Epoch 2/2

  1/unk [-] - Loss: 1.763

  2/unk [\] - Loss: 1.6215

  3/unk [|] - Loss: 1.6819

  1/unk [-] - Loss: 1.659

  2/unk [\] - Loss: 1.4758

  3/unk [|] - Loss: 1.6868


  4/unk [/] - Loss: 1.34 
  Train metrics: Loss: 1.6819
  Valid metrics: Loss: 1.34


mlverse/luz documentation built on Sept. 19, 2024, 11:20 p.m.