Comments (2)
RLlib's Policy
class has the function export_model
, which is used for exporting raw learning framework model with options to save as ONNX model.
So the problem falls back to how to load the checkpoint MARLlib saved. I've personally wrote a script to load the checkpoint + params.json
. You can reuse the load_model
function to retreive the policy, and then export it:
from eval import load_model
ckpt = load_model(
{
"model_path": "best_model/checkpoint",
"params_path": "best_model/params.json",
}
)
env = marl.make_env(environment_name=ckpt.env_name, map_name=ckpt.map_name)
env_instance, env_info = env
# Change the policy name accordingly
policy = ckpt.trainer.get_policy("shared_policy")
policy.export_model("/directoty/to/save")
PS: In case anybody want to know how to use the raw model:
model = policy.model
state = policy.get_initial_state()
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
def get_obs(env):
obs = env.observation_space.sample()
# Suppose observation is a dict. E.g.
# obs = {
# "action_mask": [0, 0, 1, 0],
# "obs": [1, 1, 4, 5, 1, 4],
# }
for key in obs:
obs[key] = torch.from_numpy(np.array([obs[key]])).to(DEVICE)
return obs
dummy_input = {
"input_dict": {"obs": get_obs(env_instance)},
"state": [torch.from_numpy(np.array(state)).to(DEVICE)],
"seq_lens": np.array([1])
}
output = model(**dummy_input)
from marllib.
Although I do not know how Ray can do that directly, I tried to unwrap a Ray checkpoint and figured out its structure.
First, load the raw checkpoint with pickle.load
, you will get a dictionary instance, whose value for key 'worker' is a bytes
instance that contains the model weights. Use pickle.loads
to get the worker status dictionary. select key 'state' and then 'weight', which will be the raw parameters for the network. You may manually pack them into a .pt
object.
from marllib.
Related Issues (20)
- Episodes_this_iter parameter
- Supporting Individual Action Spaces
- How do I get an agent's position in the environment in the `postprocess_trajectory` method? HOT 1
- IQL setup for Custom Env
- Can the qmix algorithm solve the AirCombat problem and does Marllib support it?
- Training agents with IQL HOT 3
- Query Regarding num_workers Setting Resulting in Multiple Concurrent Environments During Training
- Inferencing the learned Policies HOT 2
- Inter-agent communication before compute_actions HOT 1
- How to set up exploration strategies for Agents?
- Confusing results in simple spread environment HOT 1
- Zero reward in Overcooked environment regardless of algorithm/length of training
- NaN rewards in custom environment HOT 2
- how to fine tune pre-trained policies for new env ?
- Outdated ray requirement (ray=1.8.0) HOT 1
- metadrive agent policy mapping: agent_n more than assigned number of agents
- Does Marllib support dynamic environments?
- Does MARLlib support a mixed scenario where each agent has a different policy?
- When running the iddpg algorithm in the MAMujoco environment, the memory keeps increasing. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marllib.