gpt_neox_client 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77a992f9cbba2e7a91141c859194cc0a200b9c5dd4e58aeedc51482ec75b8c0
4
- data.tar.gz: 302c37b125a0875463859b62fb7918b47c38cd521ad444fe758a36ba06e27ade
3
+ metadata.gz: e76735b1c4c6a4e228620bd4cd3ab20d02d0b20505eb85acbcab263301ad4e49
4
+ data.tar.gz: 05d285d7b1daa24408c1087f0c748a456a8398d45c59b3b311e1d0a4413df00a
5
5
  SHA512:
6
- metadata.gz: a3ab1eb43db87f08e24fb16181d83feeb4b1421fd601165a233cc48eccfd0403de2e1d98042e89e259c843e5c3021e3931d57f4742ee20ae8c7e55cf45f6c0d4
7
- data.tar.gz: 88f961e5a901ea5896486b4612ab3ecc8ebcbad12726fd76700bb1248e31c11716ae4a7248592f7657fb056e36af19f466f95860862a4d165fc026df3d4cb04f
6
+ metadata.gz: dda9974e3d4d1023ec0e8783922c6cb779b41d0083aa26bdfb73e69778de353eee9b26d5185ea0f160bec07df89ec9f34267dd2c42e02f0d95bc224fb4b4a43a
7
+ data.tar.gz: 0a2c389774a0e49b8b6f4ee2dac8bea96f5d1608ef4b4ac9cef95f29480fc23f4cbc19c14be97781e9076eee3a9fd247883c979390ff1fd2385159c42a12189e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-09-xx
3
+ ## [0.2.0] - 2023-09-02
4
+
5
+ - Add Accelerate framework and Metal build option for macOS.
6
+ - Add OpenBLAS build option for platforms other than macOS.
7
+
8
+ ## [0.1.0] - 2023-09-01
4
9
 
5
10
  - Initial release
data/README.md CHANGED
@@ -38,15 +38,15 @@ japanese-large-lm-3.6b-instruction-sft/ggml-model-f16.bin
38
38
  ```
39
39
 
40
40
  ```ruby
41
- require "gpt_neox_client"
41
+ require 'gpt_neox_client'
42
42
 
43
- client = GPTNeoXClient.new('japanese-large-lm-3.6b-instruction-sft/ggml-model-f16.bin', seed: 123456789, n_threads: 4)
43
+ client = GPTNeoXClient.new(path: 'japanese-large-lm-3.6b-instruction-sft/ggml-model-f16.bin', seed: 123456789, n_threads: 4)
44
44
  puts client.completions(
45
45
  'ユーザー:四国の県名を全て列挙してください。<0x0A>システム:',
46
46
  top_p: 0.9,
47
47
  top_k: 1,
48
48
  temperature: 0.7
49
- ).gsub("<0x0A>", "\n").gsub("</s>", " ")
49
+ ).gsub('<0x0A>', "\n").gsub('</s>', '')
50
50
  #
51
51
  # ユーザー:四国の県名を全て列挙してください。
52
52
  # システム:徳島県、香川県、愛媛県、高知県
@@ -22,4 +22,30 @@ $INCFLAGS << ' -I$(srcdir)/src/ggml'
22
22
  $VPATH << '$(srcdir)/src'
23
23
  $VPATH << '$(srcdir)/src/ggml'
24
24
 
25
+ if RUBY_PLATFORM.match?(/darwin|linux|bsd/) && try_compile('#include <stdio.h>', '-pthread')
26
+ $CFLAGS << ' -pthread'
27
+ $CXXFLAGS << ' -pthread'
28
+ end
29
+
30
+ if RUBY_PLATFORM.match?(/darwin/)
31
+ if have_framework('Accelerate')
32
+ $CFLAGS << ' -DGGML_USE_ACCELERATE'
33
+ else
34
+ warning 'Accelerate framework is not found.'
35
+ end
36
+ end
37
+
38
+ $CFLAGS << ' -DGGML_USE_OPENBLAS' if !RUBY_PLATFORM.match?(/darwin/) && (have_library('openblas') && have_header('cblas.h'))
39
+
25
40
  create_makefile('gpt_neox_client/gpt_neox_client')
41
+
42
+ if RUBY_PLATFORM.match?(/darwin/)
43
+ File.open('Makefile', 'a') do |f|
44
+ f.puts "\nggml-metal.o: ggml-metal.m ggml-metal.h"
45
+ f.puts "\t$(CC) $(CFLAGS) -c $< -o $@"
46
+ end
47
+
48
+ metal_path = File.expand_path("#{__dir__}/src/ggml/ggml-metal.metal")
49
+ dest_path = File.expand_path("#{__dir__}/../../lib/gpt_neox_client/")
50
+ FileUtils.cp(metal_path, dest_path)
51
+ end
@@ -208,6 +208,7 @@ static VALUE gpt_neox_client_completions(int argc, VALUE* argv, VALUE self) {
208
208
  std::mt19937 rng(seed);
209
209
  std::vector<gpt_vocab::id> embd;
210
210
  std::vector<int32_t> last_n_tokens(model->hparams.n_ctx, 0);
211
+ gpt_vocab::id token_eos = vocab->token_to_id["</s>"];
211
212
 
212
213
  while (n_sampled < n_predict) {
213
214
  if (embd.size() > 0) {
@@ -240,7 +241,7 @@ static VALUE gpt_neox_client_completions(int argc, VALUE* argv, VALUE self) {
240
241
  }
241
242
 
242
243
  for (auto id : embd) completions += vocab->id_to_token[id];
243
- if (embd.back() == 0) break;
244
+ if (!embd.empty() && embd.back() == token_eos) break;
244
245
  }
245
246
 
246
247
  RB_GC_GUARD(prompt_);
@@ -3,5 +3,5 @@
3
3
  # GPTNeoXClient is a Ruby client for GPT-NeoX.
4
4
  class GPTNeoXClient
5
5
  # The version of GPTNeoXClient you are using.
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpt_neox_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-01 00:00:00.000000000 Z
11
+ date: 2023-09-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: gpt_neox_client is a simple client for GPT-NeoX.
14
14
  email: