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

fix output error when parallel_requests > 1 and supports_multiple_generations is False #864

Conversation

arjun-krishna1
Copy link
Contributor

@arjun-krishna1 arjun-krishna1 commented Aug 29, 2024

Resolve: #861 (comment)

  • FIX Probes fail with nim generator when parallel_requests > 1
  • Error: TypeError: expected string or bytes-like object, got 'list'
  • When a generator's 'supports_multiple_generations' is false
  • And the 'parallel_requests' > 1,
  • Ensure the generator output is added as a string, not a list.

@arjun-krishna1 arjun-krishna1 force-pushed the bugfix/nim-generator-fix-expected-string-got-list branch from fcd7bce to bac3634 Compare August 29, 2024 23:11
@arjun-krishna1
Copy link
Contributor Author

This branch fixes error: TypeError: expected string or bytes-like object, got 'list'
On main when nim generator is run with parallel_requests > 1

(.venv) arjun@arjun-ThinkPad-L14-Gen-3:~/garak$ python -m garak -m nim -n nvidia/nemotron-mini-4b-instruct -p xss --parallel_requests 2
garak LLM vulnerability scanner v0.9.0.15.post1 ( https://github.com/leondz/garak ) at 2024-08-29T19:19:55.972963
📜 logging to /home/arjun/.local/share/garak/garak.log
🦜 loading generator: NIM: nvidia/nemotron-mini-4b-instruct
📜 reporting to /home/arjun/.local/share/garak/garak_runs/garak.8a08484d-3ff3-4714-ac76-e79d9058d497.report.jsonl
🕵️  queue of probes: xss.MarkdownImageExfil
Traceback (most recent call last):                                                                                                                                                              
  File "<frozen runpy>", line 198, in _run_module_as_main                                                                                                                                       
  File "<frozen runpy>", line 88, in _run_code
  File "/home/arjun/garak/garak/__main__.py", line 14, in <module>
    main()
  File "/home/arjun/garak/garak/__main__.py", line 9, in main
    cli.main(sys.argv[1:])
  File "/home/arjun/garak/garak/cli.py", line 509, in main
    command.probewise_run(
  File "/home/arjun/garak/garak/command.py", line 222, in probewise_run
    probewise_h.run(generator, probe_names, evaluator, buffs)
  File "/home/arjun/garak/garak/harnesses/probewise.py", line 107, in run
    h.run(model, [probe], detectors, evaluator, announce_probe=False)
  File "/home/arjun/garak/garak/harnesses/base.py", line 122, in run
    d.detect(attempt)
  File "/home/arjun/garak/garak/detectors/xss.py", line 28, in detect
    results.append(1.0 if re.search(_MARKDOWN_REGEX, output) else 0.0)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/re/__init__.py", line 177, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'list'
(.venv) arjun@arjun-ThinkPad-L14-Gen-3:~/garak$ git checkout bugfix/nim-generator-fix-expected-string-got-list 
Switched to branch 'bugfix/nim-generator-fix-expected-string-got-list'
(.venv) arjun@arjun-ThinkPad-L14-Gen-3:~/garak$ python -m garak -m nim -n nvidia/nemotron-mini-4b-instruct -p xss --parallel_requests 2
garak LLM vulnerability scanner v0.9.0.15.post1 ( https://github.com/leondz/garak ) at 2024-08-29T19:21:42.243693
📜 logging to /home/arjun/.local/share/garak/garak.log
🦜 loading generator: NIM: nvidia/nemotron-mini-4b-instruct
📜 reporting to /home/arjun/.local/share/garak/garak_runs/garak.4b3ce712-1647-49e1-a998-8ed1e8b68718.report.jsonl
🕵️  queue of probes: xss.MarkdownImageExfil
xss.MarkdownImageExfil                                                        xss.MarkdownExfilBasic: PASS  ok on  120/ 120                                                                     
xss.MarkdownImageExfil                                                      xss.MarkdownExfilContent: PASS  ok on  120/ 120                                                                     
📜 report closed :) /home/arjun/.local/share/garak/garak_runs/garak.4b3ce712-1647-49e1-a998-8ed1e8b68718.report.jsonl
📜 report html summary being written to /home/arjun/.local/share/garak/garak_runs/garak.4b3ce712-1647-49e1-a998-8ed1e8b68718.report.html
✔️  garak run complete in 94.20s
(.venv) arjun@arjun-ThinkPad-L14-Gen-3:~/garak$ 

@arjun-krishna1 arjun-krishna1 force-pushed the bugfix/nim-generator-fix-expected-string-got-list branch from bac3634 to 06320b0 Compare August 30, 2024 00:13
Signed-off-by: Arjun Krishna <arjunkrishna1306@gmail.com>
Signed-off-by: Arjun Krishna <arjunkrishna1306@gmail.com>
@arjun-krishna1 arjun-krishna1 force-pushed the bugfix/nim-generator-fix-expected-string-got-list branch from 06320b0 to 4cfe201 Compare August 30, 2024 00:13
leondz
leondz previously requested changes Aug 30, 2024
Copy link
Owner

@leondz leondz left a comment

Choose a reason for hiding this comment

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

Thanks for this. It looks like there is an issue around outputs being built when parallel_requests > 1, because outputs should be a list of strings and Nones, but the output of _call_model (a list of strings/nones) is appended to it.

Recommendations:

  • Rename this PR to be about parallel_requests
  • Check that _call_model is returning just one result at a time in the Pool content
  • Move the tests out of test_nim

garak/generators/base.py Show resolved Hide resolved
tests/generators/test_nim.py Outdated Show resolved Hide resolved
tests/generators/test_nim.py Outdated Show resolved Hide resolved
tests/generators/test_nim.py Outdated Show resolved Hide resolved
@leondz leondz changed the title FIX nim generator list error when parallel_attempts > 1 FIX generator list error when parallel_requests > 1 Aug 30, 2024
@arjun-krishna1 arjun-krishna1 changed the title FIX generator list error when parallel_requests > 1 Output format error for parallel_requests > 1 and supports_multiple_generations = False Aug 30, 2024
@arjun-krishna1 arjun-krishna1 changed the title Output format error for parallel_requests > 1 and supports_multiple_generations = False Output format error for parallel_requests > 1 and supports_multiple_generations is False Aug 30, 2024
@arjun-krishna1 arjun-krishna1 changed the title Output format error for parallel_requests > 1 and supports_multiple_generations is False Output error for parallel_requests and supports_multiple_generations is False Aug 30, 2024
@arjun-krishna1 arjun-krishna1 changed the title Output error for parallel_requests and supports_multiple_generations is False Output error for parallel_requests and supports_multiple_generations is False Aug 30, 2024
@arjun-krishna1 arjun-krishna1 changed the title Output error for parallel_requests and supports_multiple_generations is False Output error for parallel_requests and supports_multiple_generations is False Aug 30, 2024
Signed-off-by: Arjun Krishna <arjunkrishna1306@gmail.com>
Signed-off-by: Arjun Krishna <arjunkrishna1306@gmail.com>
Signed-off-by: Arjun Krishna <arjunkrishna1306@gmail.com>
@arjun-krishna1 arjun-krishna1 changed the title Output error for parallel_requests and supports_multiple_generations is False Fix output error when parallel_requests > 1 and supports_multiple_generations is False Aug 30, 2024
@arjun-krishna1 arjun-krishna1 changed the title Fix output error when parallel_requests > 1 and supports_multiple_generations is False fix output error when parallel_requests > 1 and supports_multiple_generations is False Aug 30, 2024
arjun-krishna1 and others added 2 commits August 30, 2024 18:02
Co-authored-by: Jeffrey Martin <jmartin@Op3n4M3.dev>
Signed-off-by: Arjun Krishna <45014214+arjun-krishna1@users.noreply.github.com>
Signed-off-by: Arjun Krishna <arjunkrishna1306@gmail.com>
@jmartin-tech jmartin-tech dismissed leondz’s stale review August 31, 2024 16:54

Changes addressed in 8187035-3551a34

@jmartin-tech jmartin-tech merged commit 9fb0bf1 into leondz:main Aug 31, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants