Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unused variables and a broadcast #180

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions example/cnn_mnist.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ program cnn_mnist
real, allocatable :: training_images(:,:), training_labels(:)
real, allocatable :: validation_images(:,:), validation_labels(:)
real, allocatable :: testing_images(:,:), testing_labels(:)
real, allocatable :: input_reshaped(:,:,:,:)
real :: acc
logical :: ok
integer :: n
integer, parameter :: num_epochs = 10

Expand Down
3 changes: 1 addition & 2 deletions example/get_set_network_params.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ program get_set_network_params
integer, parameter :: test_size = 30
real :: xtest(test_size), ytest(test_size)
real :: ypred1(test_size), ypred2(test_size)
integer :: i, n, nparam
real, allocatable :: parameters(:)
integer :: i, n

print '("Getting and setting network parameters")'
print '(60("="))'
Expand Down
6 changes: 3 additions & 3 deletions example/quadratic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ program quadratic_fit
real, allocatable :: x(:), y(:) ! training data
real, allocatable :: xtest(:), ytest(:) ! testing data

integer :: i, n
integer :: i

print '("Fitting quadratic function")'
print '(60("="))'
Expand Down Expand Up @@ -277,7 +277,7 @@ subroutine rmsprop_optimizer( &
real, intent(in) :: xtest(:), ytest(:)
real, intent(in) :: learning_rate, decay_rate
integer, intent(in) :: num_epochs
integer :: i, j, n
integer :: i, n
real, allocatable :: ypred(:)

print '(a)', 'RMSProp optimizer'
Expand Down Expand Up @@ -446,4 +446,4 @@ subroutine shuffle(arr)
end do
end subroutine shuffle

end program quadratic_fit
end program quadratic_fit
6 changes: 1 addition & 5 deletions src/nf/nf_network_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,10 @@ module subroutine train(self, input_data, output_data, batch_size, &
integer, intent(in) :: epochs
class(optimizer_base_type), intent(in), optional :: optimizer
class(loss_type), intent(in), optional :: loss
class(optimizer_base_type), allocatable :: optimizer_

real :: pos
integer :: dataset_size
integer :: batch_start, batch_end
integer :: batch_start
integer :: i, j, n
integer :: istart, iend, indices(2)

Expand Down Expand Up @@ -600,11 +599,9 @@ module subroutine train(self, input_data, output_data, batch_size, &
! Pull a random mini-batch from the dataset
call random_number(pos)
batch_start = int(pos * (dataset_size - batch_size + 1)) + 1
batch_end = batch_start + batch_size - 1

! FIXME shuffle in a way that doesn't require co_broadcast
call co_broadcast(batch_start, 1)
Comment on lines 600 to 604
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be called outside the loop by creating an array batch_start(:) and by co_broadcasting it only once

call co_broadcast(batch_end, 1)

! Distribute the batch in nearly equal pieces to all images
indices = tile_indices(batch_size)
Expand All @@ -628,7 +625,6 @@ module subroutine update(self, optimizer, batch_size)
class(network), intent(in out) :: self
class(optimizer_base_type), intent(in), optional :: optimizer
integer, intent(in), optional :: batch_size
class(optimizer_base_type), allocatable :: optimizer_
integer :: batch_size_
real, allocatable :: params(:)
integer :: n
Expand Down
2 changes: 1 addition & 1 deletion test/test_flatten_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ program test_flatten_layer

type(layer) :: test_layer, input_layer
type(network) :: net
real, allocatable :: input_data(:,:,:), gradient(:,:,:)
real, allocatable :: gradient(:,:,:)
real, allocatable :: output(:)
logical :: ok = .true.

Expand Down
1 change: 0 additions & 1 deletion test/test_get_set_network_params.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ program test_get_set_network_params
use nf, only: conv2d, dense, flatten, input, maxpool2d, network
implicit none
type(network) :: net
integer :: n
logical :: ok = .true.
real :: test_params_dense(8) = [1, 2, 3, 4, 5, 6, 7, 8]
real :: test_params_conv2d(10) = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Expand Down
2 changes: 1 addition & 1 deletion test/test_optimizers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ program test_optimizers
real, allocatable :: x(:), y(:)
real, allocatable :: ypred(:)
integer, parameter :: num_iterations = 1000
integer :: n, i
integer :: n
logical :: ok = .true.
logical :: converged = .false.

Expand Down
Loading