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

sample: Add output file option #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions doc/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ The sampling script `sample.lua` accepts the following command-line flags:
- `-gpu`: The ID of the GPU to use (zero-indexed). Default is 0. Set this to -1 to run in CPU-only mode.
- `-gpu_backend`: The GPU backend to use; either `cuda` or `opencl`. Default is `cuda`.
- `-verbose`: By default just the sampled text is printed to the console. Set this to 1 to also print some diagnostic information.
- `-output`: By default sampled text gets output to standard output, together with diagnostic messages. This option specifies the file to output the result.
10 changes: 9 additions & 1 deletion sample.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cmd:option('-temperature', 1)
cmd:option('-gpu', 0)
cmd:option('-gpu_backend', 'cuda')
cmd:option('-verbose', 0)
cmd:option('-output', '-')
local opt = cmd:parse(arg)


Expand All @@ -39,4 +40,11 @@ if opt.verbose == 1 then print(msg) end
model:evaluate()

local sample = model:sample(opt)
print(sample)
if opt.output == "-" then
print(sample)
else
require 'io'
local outfile = io.open(opt.output, "w")
outfile:write(sample)
outfile:close()
end