docs(README): update quick start guide and add custom Bootcamp creation instructions

- Update quick start guide for data generation, model training, and evaluation
- Add detailed instructions for creating custom Bootcamp tasks
- Update examples in both English and Chinese documentation
This commit is contained in:
chenyongkang 2025-06-16 16:45:20 +08:00
parent d47b4efa33
commit 31ce74fe1c
4 changed files with 459 additions and 28 deletions

View file

@ -1,24 +1,23 @@
# Quick Start
**InternBootcamp** provides functionalities such as data generation, model training, and model evaluation. You can refer to the following guide to get started quickly.
InternBootcamp provides functionalities such as data generation, model training, model evaluation, and custom Bootcamp creation. Please refer to the following guide for a quick start.
To ensure successful execution of the following steps, please make sure **InternBootcamp is installed**, and **the project root directory is set as your working directory**.
To ensure the successful execution of subsequent operations, make sure you have installed InternBootcamp and set the project root directory as your working directory.
## Data Generation
Run [**run\_pipeline.sh**](examples/pipelines/run_pipeline.sh) to generate training and testing data based on the [default configuration](examples/pipelines/data_configs).
For custom configurations, please refer to the [Pipeline Usage Guide](examples/pipelines/README.md) for personalized setup.
Running [**run_pipeline.sh**](/examples/pipelines/run_pipeline.sh) will generate corresponding test and training data based on the **default configuration**`examples/pipelines/data_configs`. If you have custom configuration needs, please refer to [Pipeline Usage](pipelines/README.md) for personalized configuration.
```bash
source examples/pipelines/run_pipeline.sh
```
The generated data will be saved in the [bootcamp\_generator\_outputs directory](examples/bootcamp_generator_outputs). Each data batch is timestamped, and the directory structure is as follows:
The generated data is saved in the **bootcamp_generator_outputs directory**`examples/bootcamp_generator_outputs`, with data batches named using timestamps. The specific directory structure is as follows:
```
examples/
├── ...
└──bootcamp_generator_outputs/
└── bootcamp_generator_outputs/
├── ...
└── 2025-xx-xx-xx:xx:xx/
├── test/
@ -31,23 +30,21 @@ examples/
└── bootcamp_n.jsonl
```
## Model Training(Reinforcement learning)
## Model Training
We provide support for two training frameworks: **Xpuyu** and **Verl**.
We provide support systems for two training frameworks (Xpuyu and Verl).
### Xpuyu
Refer to the [Xpuyu documentation](examples/xpuyu_usage/README.md) to get started with efficient training.
Refer to the [Xpuyu documentation](/examples/xpuyu_usage/README.md) for efficient training.
### Verl
To integrate Bootcamp tasks into the Verl framework for training, you need to embed the Bootcamp reward computation method into Verl.
See the [Verl documentation](examples/verl_usage/README.md) for detailed guidance.
To incorporate Bootcamp tasks into training within the Verl framework, you need to embed the Bootcamp reward calculation method into the Verl framework according to the instructions. For details, see the [Verl documentation](/examples/verl_usage/README.md).
## Model Evaluation
For Bootcamp tasks, we offer a customized evaluation service.
Once the model to be evaluated is deployed using frameworks like FastChat or Ollama, and you have the corresponding API URL and API Key, you can run the following command to evaluate your deployed model on the **InternBootcamp\_eval** dataset:
We offer personalized evaluation services for Bootcamp tasks. After deploying the model to be tested using frameworks like FastChat or Ollama and obtaining the corresponding API URL and API Key, use the following command to quickly evaluate the performance of the deployed model on the **InternBootcamp_eval** dataset:
```bash
cd InternBootcamp
@ -66,9 +63,216 @@ python examples/unittests/run_eval.py \
--max_retrying_delay 60
```
**Note:** When `api_mode` is set to `completion`, be sure to correctly specify the corresponding template (supported: `r1`, `qwen`, `internthinker`, `chatml` (with no system prompt)).
For more detailed instructions, refer to the [Evaluation Manual](examples/unittests/README.md).
Note: When `api_mode` is set to `completion`, ensure that the corresponding `template` is correctly configured (supported options include `r1`, `qwen`, `internthinker`, and `chatml` (no system prompt)). For more details, refer to the [Evaluation Manual](/examples/unittests/README.md).
---
## Custom Bootcamp
Let me know if youd like a version with clearer formatting for publishing or documentation.
If you need to create a custom Bootcamp task, follow these steps:
### 1. Create a new subdirectory under the `internbootcamp/bootcamp` directory, named after the Bootcamp task name
In this directory, you can define multiple versions of the task class. Below is an example using `binary_arithmetic_operations_default.py` (implementing a binary arithmetic operation Bootcamp) to demonstrate the entire process of creating a custom Bootcamp.
### 2. Create a Bootcamp class, inherit from the `Basebootcamp` class, and implement the `__init__` method
- The class name must end with `bootcamp`.
- Avoid defining mutable variables like `list` in the `__init__` method (recommended to define them in the `case_generator` method) to prevent non-reset variables from being reused.
- Avoid fixing random variables here (recommended to determine random variables in the `case_generator` method) to avoid generating repetitive data due to lack of randomness.
- Input parameters for the `__init__` method are configured via JSON files located in **examples/pipelines/puzzle_configs**, ensuring the JSON configuration file name matches the Bootcamp class name, e.g., `BinaryArithmeticOperationsbootcamp_test.json`, `BinaryArithmeticOperationsbootcamp_train.json`.
```python
from internbootcamp.bootcamp.base import Basebootcamp
class BinaryArithmeticOperationsbootcamp(Basebootcamp):
def __init__(self, operands_range=(0, 10), precision=3, operators=['+', '-', '*', '/']):
self.operands_range = operands_range
self.precision = precision
self.operators = operators
def case_generator(self):
pass
def prompt_func(self, identity) -> dict:
pass
@staticmethod
def extract_output(output):
pass
@classmethod
def _verify_correction(cls, solution, identity: dict):
pass
```
### 3. Implement the `case_generator` method (optional if no data generation is needed)
`case_generator` is an instance method used to generate parameters required to construct a single question or validate a response (i.e., parameters that uniquely determine a question), returning a parameter dictionary.
```python
import random
def case_generator(self) -> dict:
operand1 = round(random.uniform(*self.operands_range), self.precision)
operand2 = round(random.uniform(*self.operands_range), self.precision)
operator = random.choice(self.operators)
while operator == '/' and operand2 == 0:
operand2 = round(random.uniform(*self.operands_range), self.precision)
case = {}
case['operand1'] = operand1
case['operand2'] = operand2
case['operator'] = operator
case['precision'] = self.precision
return case
```
### 4. Implement the `prompt_func` method (optional if no data generation is needed)
`prompt_func` is an instance, static, or class method used to construct the problem statement for a single question, taking the parameter dictionary returned by `case_generator` as input `identity`, and returning the problem statement as a string.
```python
def prompt_func(self, identity: dict) -> str:
return f"{identity['operand1']} {identity['operator']} {identity['operand2']} = ? Results should be rounded to {identity['precision']} decimal places and enclosed in double brackets like [[result]]."
```
### 5. Implement the `extract_output` method to extract answers from the model output
`extract_output` is a static method that accepts the model output as input `output` and returns the answer in any form.
```python
import re
@staticmethod
def extract_output(output):
matches = re.findall(r'\[\[([^\[\]]+)\]\]', output)
return matches[-1].strip() if matches else None
```
### 6. Implement the `_verify_correction` method to validate whether the model-generated answer is correct
`_verify_correction` is a class method that accepts the model output and the output of `case_generator` as input parameters `solution` and `identity`, returning a boolean indicating whether the answer is correct or a float/integer between 0 and 1 indicating the degree of correctness.
```python
@classmethod
def _verify_correction(cls, solution, identity: dict) -> bool:
try:
# Convert the string-form answer to a float
solution = float(solution)
except (ValueError, TypeError):
return False
# Calculate the correct answer based on the problem parameters
operand1 = identity['operand1']
operand2 = identity['operand2']
operator = identity['operator']
precision = identity['precision']
if operator == '+':
correct_answer = operand1 + operand2
elif operator == '-':
correct_answer = operand1 - operand2
elif operator == '*':
correct_answer = operand1 * operand2
elif operator == '/':
# Check for division by zero
if operand2 == 0:
return False
correct_answer = operand1 / operand2
else:
raise ValueError(f"Unsupported operator: {operator}")
# Round the correct answer to the specified precision
correct_answer = round(correct_answer, precision)
# Compare the model output with the correct answer
return abs(solution - correct_answer) < 1e-6
```
### 7. Configure the JSON file (optional if no data generation is needed)
Create a JSON configuration file consistent with the Bootcamp class name (e.g., `BinaryArithmeticOperationsbootcamp_train.json`) in the `examples/pipelines/puzzle_configs` directory to define the task parameters. Below is an example configuration:
```json
[
{
"operands_range": [-10, 10],
"precision": 3,
"operators": ["+", "-", "*", "/"]
},
{
"operands_range": [10, 1000],
"precision": 4,
"operators": ["+", "-", "*", "/"]
}
]
```
Ensure that the keys in the JSON file match the parameter names in the `__init__` method.
### 8. Register the custom Bootcamp task
To enable the system to recognize and load the custom Bootcamp task, register the task in `internbootcamp/bootcamp/__init__.py`. For example:
```python
from .binary_arithmetic_operations.binary_arithmetic_operations_default import BinaryArithmeticOperationsbootcamp
```
### 9. Test the custom Bootcamp task
After completing the above steps, you can test the custom Bootcamp task as follows:
1. Use `case_generator` to generate test cases.
2. Call `prompt_func` to generate the problem statement.
3. Use `extract_output` to extract answers from the model output.
4. Call `_verify_correction` to verify the correctness of the answer.
Below is a simple test code example:
```python
if __name__ == "__main__":
# Initialize the Bootcamp task
bootcamp = BinaryArithmeticOperationsbootcamp(
operands_range=(0, 10),
precision=3,
operators=['+', '-', '*', '/']
)
# Generate a test case
case = bootcamp.case_generator()
print("Generated Case:", case)
# Construct the problem statement
prompt = bootcamp.prompt_func(case)
print("Prompt:", prompt)
# Simulate model output
answer = eval(f"{case['operand1']} {case['operator']} {case['operand2']}")
model_output = f"[[{round(answer, 3)}]]"
extracted_answer = bootcamp.extract_output(model_output)
print("Extracted Answer:", extracted_answer)
# Verify the answer
is_correct = bootcamp._verify_correction(extracted_answer, case)
print("Is Correct:", is_correct)
```
### 10. Integrate into Pipeline (optional if no data generation is needed)
To integrate the custom Bootcamp task into the data generation pipeline, simply add the corresponding task definition to the two configuration files in the `examples/pipelines/data_configs` directory. For example:
```json
{
"bootcamp_name": "BinaryArithmeticOperations",
"sample_number": 64,
"config_file": "BinaryArithmeticOperations",
"bootcamp_cls_name": "BinaryArithmeticOperationsbootcamp"
}
```
Where:
- `bootcamp_name` is the task name (i.e., the class name without the `bootcamp` suffix).
- `sample_number` is the number of samples to generate.
- `config_file` is the configuration file name.
- `bootcamp_cls_name` is the task class name.
Alternatively, run the script [quickgen_data_configs.py](/examples/pipelines/quickgen_data_configs.py), which automatically generates corresponding pipeline configurations for Bootcamps configured in `examples/pipelines/puzzle_configs` and saves them in `examples/pipelines/data_configs`.
**By following the above steps, you can successfully create, test, and integrate a custom Bootcamp task!**