chengchingwen / Transformers.jl

Julia Implementation of Transformer models
MIT License
526 stars 75 forks source link

parse args fails #67

Closed lazarusA closed 3 years ago

lazarusA commented 3 years ago

Also, this line not longer works.

https://github.com/chengchingwen/Transformers.jl/blob/5478c020dffcb06f9eebf79859a79937a91c30da/example/AttentionIsAllYouNeed/0-data.jl#L23

with the following env

(transformersApproach) pkg> st
      Status `~/transformersApproach/Project.toml`
  [c7e460c6] ArgParse v1.1.4
  [052768ef] CUDA v3.3.4
  [587475ba] Flux v0.12.5
  [21ca0261] Transformers v0.1.13
  [796a5d58] WordTokenizers v0.5.6
  [e88e6eb3] Zygote v0.6.17
chengchingwen commented 3 years ago

What do you mean? It works fine for me.

lazarusA commented 3 years ago

if do: (I'm also testing attention is all you need)

using ArgParse
using Flux, CUDA
using Flux: onecold, gradient, onehot
import Flux.Optimise: update!

using WordTokenizers

using Transformers
using Transformers.Basic

using Random
Random.seed!(0)

using Transformers.Datasets
using Transformers.Datasets: WMT, IWSLT

function parse_commandline()
  s = ArgParseSettings()

  @add_arg_table s begin
    "--gpu", "-g"
    help = "use gpu"
    action = :store_true

    "task"
    help = "task name"
    required = true
    range_tester = x-> x ∈ ["wmt14", "iwslt2016", "copy"]
  end
  return parse_args(ARGS, s)
end
const args = parse_commandline()

then this errors:

ERROR: ArgParseError("required argument task was not provided")
Stacktrace:
 [1] argparse_error(x::Any)
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/parsing.jl:9
 [2] test_required_args(settings::ArgParseSettings, found_args::Set{AbstractString})
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/parsing.jl:44
 [3] parse_args_unhandled(args_list::Vector{T} where T, settings::ArgParseSettings, truncated_shopts::Bool)
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/parsing.jl:639
 [4] parse_args_unhandled(args_list::Vector{T} where T, settings::ArgParseSettings)
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/parsing.jl:595
 [5] parse_args(args_list::Vector{T} where T, settings::ArgParseSettings; as_symbols::Bool)
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/parsing.jl:469
 [6] parse_args(args_list::Vector{T} where T, settings::ArgParseSettings)
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/parsing.jl:466
 [7] parse_commandline()
   @ Main ~/transformersApproach/0-data.jl:30
 [8] top-level scope
   @ REPL[3]:1

this is the output from ArgParseSettings(), if that helps.

ArgParseSettings()
ArgParseSettings(
  prog=
  description=
  epilog=
  usage=
  version=Unspecified version
  add_help=true
  add_version=false
  fromfile_prefix_chars=Set{Char}()
  autofix_names=false
  error_on_conflict=true
  suppress_warnings=false
  allow_ambiguous_opts=false
  commands_are_required=true
  default_group=
  exc_handler=default_handler
  preformatted_description=false
  preformatted_epilog=false
  exit_after_help=false
  >> usage: <PROGRAM>
  )
chengchingwen commented 3 years ago

You need to run the code with the task argument. For example: $ julia --proj -i 1-model.jl copy

lazarusA commented 3 years ago

and here, yes of course, now I see it. However, using things like this just works with a final product [which is what you have here], however for debugging I find it a little bit cumbersome. For instance, here I also got the onehot error in this line

https://github.com/chengchingwen/Transformers.jl/blob/5478c020dffcb06f9eebf79859a79937a91c30da/example/AttentionIsAllYouNeed/1-model.jl#L53

Another comment: I noticed that you have 2 train!() functions in the 0-data.jl file, and when running the code I believe the second one is used. I suppose both are ok. Plus, there is not a test section or test example which will be nice to have :D

Things seems to work. Now to the real problem. Thanks.

Oblynx commented 3 years ago

Hi, I had exactly the same issue just now :) I'll add a README if that's ok!

chengchingwen commented 3 years ago

Another comment: I noticed that you have 2 train!() functions in the 0-data.jl file, and when running the code I believe the second one is used. I suppose both are ok.

the 2 train! function are used for different task depend on the task you choose.

Plus, there is not a test section or test example which will be nice to have :D

There is a translate function you could use to play with your model. The code is only meant to be run in the REPL to do some simple test, but you should be able to easily modified it for your own task if you are familiar with Flux