Skip to main content

SQLGym: A portable Gymnasium environment of SQLite database.

Project description

SQLGym

This is a portable Gymnasium environment of SQLite database. It is designed for platforms that are not able to use docker. (e.g. users without root privillege)

Setup

Simply pip install sqlgym. If you want to generate ReAct dataset and fine tune a model, please clone the repository and install from source.

# Clone this repository
git clone https://github.com/KYLN24/sqlgym.git
# or via SSH
# git clone git@github.com:KYLN24/sqlgym.git

cd sqlgym

# Install this package
pip install ".[sft]"

Prepare Dataset

# Make a directory to save data
mkdir .data
cd .data

This project currently suppport the BIRD-SQL dataset.

mkdir bird
cd bird

# Download BIRD-SQL Dataset
wget -c https://bird-bench.oss-cn-beijing.aliyuncs.com/train.zip
unzip train.zip
cd train
unzip train_databases.zip
cd ..

wget -c https://bird-bench.oss-cn-beijing.aliyuncs.com/dev.zip
unzip dev.zip
cd dev
unzip dev_databases.zip
cd ..

Usage

from sqlgym import SqlGymEnv
from sqlgym.datasets import BirdDataset

dataset = BirdDataset(
    bird_path=".data/bird",
    mode="dev",
)

env = SqlGymEnv(dataset)

print(env.reset(0))
print(env.step(dataset[0].gt))

SFT

You can use scripts/make_datasets.py to generate a SFT dataset.

python -u scripts/make_datasets.py --bird_path=./data/bird # Dataset will be created at ./data/bird/train.jsonl and ./data/bird/dev.jsonl

You can use scripts/make_react_dataset.py to convert it to ReAct format with thought generated by GPT.

# Edit the script to add your OpenAI api_key.
# Change base_url and other generation parameters as you wish.
python -u scripts/make_react_dataset.py \
       --data_path=.data/bird/train.jsonl \
       --save_path=.data/bird/train_react.jsonl

Then, use scripts/train.py or scripts/train_react.py to fine tune a chat model. The tokenizer should support the apply_chat_template method.

torchrun --nproc_per_node=8 scripts/train.py \
         --model=meta-llama/Llama-2-7b-chat-hf \
         --train_set=.data/bird/train.jsonl \
         --output_dir=.data/output

torchrun --nproc_per_node=8 scripts/train.py \
         --model=meta-llama/Llama-2-7b-chat-hf \
         --train_set=.data/bird/train_react.jsonl \
         --output_dir=.data/output \
         --react

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlgym-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sqlgym-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sqlgym-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sqlgym-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03ac307c8a05e1d017e88ef8937901bc64c999c3644920483c6aa3c24c0314fa
MD5 2aef8997b3c61b60089b7ace57105600
BLAKE2b-256 c9bd180add35e1c82b74df4183e9c04a7ebc2aff2e3d8f1204843d2ebc63f154

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page